我面临一个问题,当我有一个复杂的模型时,如果我提交表单,它不会给我所有模型属性的所有值,在下面的示例中,我没有取回 gridModel 属性:
模型
public class InventoryModel {
public GridModel GridModel { get; set; }
public Int32 UserKey { get; set; }
}
public class GridModel {
public String GridId { get; set; }
public String GridName { get; set; }
public List<String> columns { get; set; }
}
控制器
public ActionResult Index(){
InventoryModel model = new InventoryModel();
model.UserKey= 20014;
model.GridModel = new GridModel();
model.GridModel.GridId = "jqgInventory";
model.GridModel.GridName = "Inventory Grid";
return View(model);
}
[HttpPost]
public ActionResult Index(InventoryModel model){
Int32 userId = model.UserKey; // This has a value
String gridId = model.GridModel.GridId; // This doesn't have a value
String gridName= model.GridModel.GridName; // This doesn't have a value
}
看法
@model InventoryModel
@using (Html.BeginForm()) {
@Html.TextBoxFor(m => m.UserKey, new { @class = "w200" })
@Html.TextBoxFor(m => m.GridModel.GridId , new { @class = "w200" })
@Html.TextBoxFor(m => m.GridModel.GridName, new { @class = "w200" })
<input type="submit" value="Submit" />
}
任何建议都将不胜感激。
谢谢,阿拉