显式绑定模型

3
一般情况下,我会使用以下代码来绑定客户模型:
[HttpPost]
public ActionResult Create(Customer model)
{
  ...
}

现在,我想推迟绑定时间,而不是立即绑定,就像这样。
[HttpPost]
public ActionResult Create()
{
  //some operations first
  ...
  //binding will start here 
  var model={Bind - To - Customer}
  ...
}

那么,我该如何实现这个目标,这是可能的吗?非常感谢任何建议。
1个回答

6
你可以使用 UpdateModelTryUpdateModel 方法:
[HttpPost]
public ActionResult Create()
{
    //some operations first
    ...
    // binding will start here 
    var model = new Customer();
    UpdateModel(customer);
    ...
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接