ASP.Net MVC4 ViewModel null properties and HttpPost -
i have following viewmodel:
public class myviewmodel { public int id { get; set; } public string title { get; set; } public int parentclassid { get; set; } public list<anotherclass> anotherclassitems { get; set; } }
and in view have form input title, , list of anotherclassitems aren't editable - used display list of items related class. of properties set when 'edit' view loads, when view post, parentclassid & anotherclassitems lists null. here httppost actionresult controller:
[httppost] public actionresult edit(formcollection collection, myviewmodel myviewmodel) { if (modelstate.isvalid) { //myviewmodel.parentclassid , myviewmodel.anotherclassitems null?? } return view(myviewmodel); }
is there way pass parentclassid & anotherclassitems properties without having them form inputs in view? or should use viewbag this?
remember, form posts html input fields. if did not make text boxes or hidden boxes not post edit action.
the correct way handle passing id hidden field, pulling original values database/repository.
then apply new values title , anotherclassitems model , save repository/database.
Comments
Post a Comment