在 ASP.Net MVC 模型绑定器中,可以创建绑定类型的对象,然后更新其属性。
例如
public override object BindModel(ControllerContext controllerContext,
ModelBindingContext bindingContext)
{
ParentType boundModel = null;
if (bindingContext.ModelType == typeof(ParentType))
{
var myFactory = new MyFactory();
var someValue = bindingContext.ValueProvider.GetValue
("someFieldId").AttemptedValue;
ChildType child = myFactory.Create(someValue);
BindModel(child);
boundModel = child;
}
return boundModel;
}
在这段代码中,我想知道是否有类似于 BindModel(child) 调用的东西,有点像来自控制器的 TryModelUpdate()?