盲目地覆盖绑定上下文的 ModelMetaData 来设置模型的类型是否安全?我担心活页夹可能会用于更新编辑场景中的预建模型,如果我只是覆盖 ModelMetaData,我会丢失数据。
示例代码:
Public Class CustomModelBinder
Inherits DefaultModelBinder
Public Overrides Function BindModel(ByVal controllerContext As ControllerContext, ByVal bindingContext As ModelBindingContext) As Object
bindingContext.ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(Nothing, GetSpecificModelTypeBasedOnBindingData(bindingContext))
Return MyBase.BindModel(controllerContext, bindingContext)
End Function
End Class