明确绑定模型

时间:2011-10-10 07:38:49

标签: c# asp.net-mvc model-binding

一般来说,我将使用下面的代码来绑定Customer模型,

[HttpPost]
public ActionResult Create(Customer model)
{
  ...
}

现在,我想稍后提高绑定,而不是立即提高绑定,就像这个

[HttpPost]
public ActionResult Create()
{
  //some operations first
  ...
  //binding will start here 
  var model={Bind - To - Customer}
  ...
}

所以,我怎么能实现这一点,是否可能???

非常感谢任何建议

1 个答案:

答案 0 :(得分:6)

您可以使用UpdateModelTryUpdateModel方法:

[HttpPost]
public ActionResult Create()
{
    //some operations first
    ...
    // binding will start here 
    var model = new Customer();
    UpdateModel(customer);
    ...
}
相关问题