1.使用MVC默认Model Binder
[AcceptVerbs("POST")]
public ActionResult Edit(Product product)
2.使用FormCollection然后自己然后手工绑定
[AcceptVerbs("POST")]
public ActionResult Edit(FormCollection form)
3.使用UpdateModel只绑定指定的属性
UpdateModel(product, new[] { "ProductName", "UnitPrice", "Discontinued", "ReorderLevel" });
4.自定绑定
ModelBinders.Binders[typeof(Product)] = new ProductBinder();
或者 [AcceptVerbs("POST")]
public ActionResult Edit([ModelBinder(typeof(ProductBinder))] Product product)
5.只去指定的属性
[AcceptVerbs("POST")]
public ActionResult Edit(string ProductName, string UnitPrice)
本文详细介绍了在ASP.NET MVC中如何使用MVC默认的ModelBinder、手动绑定、指定属性绑定以及自定义绑定方法来实现参数的代理绑定,包括使用FormCollection和UpdateModel进行数据绑定,并探讨了自定义ModelBinder的实现。
399

被折叠的 条评论
为什么被折叠?



