sim*_*man 3 c# asp.net-mvc model-binding
一般来说,我将使用下面的代码来绑定客户模型,
[HttpPost]
public ActionResult Create(Customer model)
{
...
}
Run Code Online (Sandbox Code Playgroud)
现在,我想稍后提高绑定,而不是立即提高绑定
[HttpPost]
public ActionResult Create()
{
//some operations first
...
//binding will start here
var model={Bind - To - Customer}
...
}
Run Code Online (Sandbox Code Playgroud)
所以,我怎么能实现这一点,是否可能?
非常感谢任何建议
你可以使用UpdateModel或TryUpdateModel方法:
[HttpPost]
public ActionResult Create()
{
//some operations first
...
// binding will start here
var model = new Customer();
UpdateModel(customer);
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
594 次 |
| 最近记录: |