我不知道为什么您认为自 MVC 1 以来关于自定义模型绑定器发生了很大变化。但是,如果我了解您要做什么,那应该很容易。
public class CustomModelBinder : DefaultModelBinder {
public override object BindModel(ControllerContext controllerContext,
ModelBindingContext bindingContext) {
NameValueCollection form = controllerContext.HttpContext.Request.Form;
//get what you need from the form collection
//creata your model
SomeModel myModel = new SomeMode();
myModel.Property = "value";
//or add some model errors if you need to
ModelStateDictionary mState = bindingContext.ModelState;
mState.Add("Property", new ModelState { });
mState.AddModelError("Property", "There's an error.");
return myModel; //return your model
}
}
而你的行动:
public ActionResult Contact([ModelBinder(typeof(CustomModelBinder))]SomeModel m){
//...
}
那是您要查找的信息吗?