asp.net mvc 4 - Getting invalid ID and Name in mvc razor when model has navigation property? -
this razor code in view.
int pmtcount = 0; if (item.projectmaterialtypes != null) { @foreach (var x in item.projectmaterialtypes) { pmtcount = pmtcount + 1; @html.hiddenfor(model =>model.projecttypes[ptcount - 1].projectmaterialtypes.tolist()[pmtcount - 1].projectmaterialtypeid, new { value = x.projectmaterialtypeid}) @html.hiddenfor(model => model.projecttypes[ptcount - 1].projectmaterialtypes.tolist()[pmtcount - 1].materialtypes.name, new { value = x.materialtypes.name }) <label>@html.checkboxfor(model => model.projecttypes[ptcount - 1].projectmaterialtypes.tolist()[pmtcount - 1].status, new { @onclick = "togglesingle('smt-" + x.materialtypeid + "')" }) @x.materialtypes.name</label> } }
populating id , name on browser.
but getting null object in controller submitting form, please let me know there way solve problem?
simply changed icollection list in model library.in way resolved issue. html helper generate property name when use list instead of icollection in entity framework model class.
from
public virtual icollection<projectmaterialtype> projectmaterialtypes { get; set; }
changed
public virtual list<projectmaterialtype> projectmaterialtypes { get; set; }
Comments
Post a Comment