c#, .net 4.5, mvc 5
referring xx1 , xx2 below (main view):
the object initialized in main controller. (both header , detial.)
i have added breakpoints @ both xx1 , xx2 confirm that initialized values still there.
- no problem xx1. initialized values there , passed , received controller.
- xx2 have problem. initialized values still there , passed to, null object somehow received by, controller.
why controller detail not pick passed parameters it.
model:
public class samplenonroutine { public headernonroutine sampleheader { get; set; } public list<detailnonroutine> sampledetail { get; set; } public string comments { get; set; } } public class headernonroutine { public string division { get; set; } public string name { get; set; } public string telephone { get; set; } [displayname("sample title")] public string sampletitle { get; set; } [displayname("retain sample for")] public int retainsample { get; set; } } public class detailnonroutine { public int id { get; set; } [displayname("sample reference #")] public string samplereference { get; set; } [displayname("sample test")] public string samplestested { get; set; } [displayname("sample assays")] public string sampleassays { get; set; } }
controller:
for parent view
public actionresult nonroutinesamples(string savesend) { samplenonroutine sample = new samplenonroutine(); sample.sampleheader = new headernonroutine(); sample.sampledetail = new list<detailnonroutine>(); sample.comments = "toets"; (int = 0; < 10; i++) { sample.sampledetail.add(new detailnonroutine { id = + 1, samplereference = "", samplestested = "", sampleassays = "" }); } return view(sample); }
for partial views:
header (partial view):
public actionresult _headernonroutinesamples(headernonroutine model) { //...some code persondetail pdetail = _db.listperson(_meperson.first().number.tostring()); model.name = pdetail.name + " " + pdetail.surname; model.telephone = pdetail.phonework; model.division = pdetail.division; model.retainsample = 30; return partialview(model); }
detail:
public actionresult _detailnonroutinesamples(list<detailnonroutine> model) { return partialview(model); }
views:
main
@model laboratorysampleregistration.models.samplenonroutine @{ viewbag.title = "nonroutinesamples"; } @using (html.beginform()) { @html.antiforgerytoken() <h4>non-routine samples</h4> <table> <tr> <td> @html.action("_headernonroutinesamples", "home", model.sampleheader) xx1 </td> </tr> <tr> <td> @html.action("_detailnonroutinesamples", "home", model.sampledetail) xx2 </td> </tr> <tr> <td> <div> @html.labelfor(model => model.comments, htmlattributes: new { @class = "control-label col-md-2" }) <div> <span> @html.textareafor(model => model.comments, new { @class = "sampleroutinecomments" }) @html.validationmessagefor(model => model.comments, "", new { @class = "text-danger" }) </span> </div> </div> </td> </tr> <tr> <td> <hr style="border-top:1px solid black !important;" /> <p> <input id="savesend" name="savesend" type="submit" value="send laboratory" class="btn btn-default" /> </p> </td> </tr> </table>
}
Comments
Post a Comment