在ASP.Net MVC模型绑定器中,可以创建绑定类型的对象,然后更新绑定类型的属性。将数据绑定到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(孩子)调用的东西,有点像从控制器TryModelUpdate()?
什么是用例? – 2010-02-19 17:40:37
我有两个子类和哪一个实例化是基于ID为“someFieldId”的下拉列表。所以我想使用工厂实例化Child类,然后使用TryUpdateModel/BindModel调用更新窗体中的所有父属性。然后我会喜欢传递给控制器的绑定模型。 – 2010-02-19 17:49:29