我的SomeModel
定义为:
public class SomeModel
{
public string property1 { get; set }
public bool property2 { get; set; }
}
我有一个动作:
public ActionResult Edit(int id)
{
SomeModel model = new SomeModel();
//... populate model ...
return View(model);
}
假设视图property1
和property2
的实例为@Html.EditorFor
,在这种情况下,property1
将呈现为<input type='text'>
和{{1将是property2
。
如果我有以下控制器操作来处理“编辑”表单中的提交:
<input type='checkbox'>
参数模型如何填充,如果有的话?
答案 0 :(得分:2)
如果您使用类似
的内容[HttpPost]
public ActionResult Action(SomeModel model)
{
//do something
}
如果您在视图中使用标准的Html.EditorFor语法,那么所有的模型绑定都会得到照顾,正如您所提到的那样。
@Html.EditorFor(model => model.Property1)
@Html.EditorFor(model => model.Property2)
有关模型绑定的更多信息here