model view controller - ViewModel is posting back null -



model view controller - ViewModel is posting back null -

ok, have view model not bound info object. building in steps , in page i'm binding viewmodel. however, want homecoming viewmodel in post can go on process. i've used typical viewmodel sample that's on codeproject.com, need have viewmodel posted because storing other info in there. created viewmodel in , send view, when submitted, viewmodel null. missing? help appreciated. i'm 3 weeks mvc. thanks.

public class registrationchildviewmodel { public ienumerable<selectlistitem> children { get; set; } public ienumerable<string> selectedchildren { get; set; } public datetime selecteddate { get; set; } public string selectedroomkey { get; set; } }

here controller (get , post)

// assign - public actionresult selectchildren() { list<selectlistitem> listselectlistitem = new list<selectlistitem>(); datetime selecteddate = convert.todatetime(tempdata["selecteddate"]); foreach (registrationchild kid in db.registrationchilds.where(item => item.registration.event.eventdate.day == selecteddate.day && item.registration.event.eventdate.month == selecteddate.month)) { selectlistitem selectlistitem = new selectlistitem() { text = child.child.name + "-" + child.registration.event.name, value = child.child.pkey.tostring() }; listselectlistitem.add(selectlistitem); } // create registration kid view model registrationchildviewmodel registrationchildviewmodel = new registrationchildviewmodel(); // set selected children registrationchildviewmodel.children = listselectlistitem; // set selected room key registrationchildviewmodel.selectedroomkey = tempdata["roomkey"].tostring(); // set selected date registrationchildviewmodel.selecteddate = selecteddate; homecoming view(registrationchildviewmodel); } [httppost] [validateantiforgerytoken] public actionresult selectchildren(registrationchildviewmodel registrationchildviewmodel) { //if (registrationchildviewmodel.selectedchildren == null) //{ // homecoming view(registrationchildviewmodel); //} //else //{ // stringbuilder sb = new stringbuilder(); // sb.append(string.join(",", registrationchildviewmodel.selectedchildren)); // homecoming view(registrationchildviewmodel); //} homecoming view(registrationchildviewmodel); }

and mvc page

@model nrms.models.registrationchildviewmodel @{ viewbag.title = "briarwood nursery registration - admin"; } <h2>@viewbag.title</h2> <h3>@viewbag.message</h3> @using (html.beginform()) { @html.antiforgerytoken() <div class="form-horizontal"> <h4>assign children</h4> <div> @html.actionlink("back parent information", "adminmenu") </div> <hr /> @model.selecteddate.toshortdatestring()<br /> @model.selectedroomkey<br /> @html.listboxfor(model => model.selectedchildren, model.children) <br /> <input type="submit" value="submit" /> </div> }

model-view-controller viewmodel

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -