我想知道是否有一种方法可以使用类似于在控制器操作之前发生的内部模型绑定的内置模型绑定。
我的问题是我希望能够控制绑定,因为在我实际处于控制器操作的上下文中之前我不会知道要绑定的对象的类型。
我知道我可以继承 DefaultModelBinder 来执行自定义绑定,但我对已经提供的东西很满意,并且只想利用它 - 以这个理想的例子来了解我所追求的:
public ActionResult DoCustomBinding(string modelType)
{
... // logic to determine type to check and create strong 'actual' type
object model = BindModel(actualType);
... // do something with bound model
return View();
}
我已经研究过使用 DefaultModelProvider,但不确定这是否是正确的方法,我不确定如何获取 ModelBindingContext。