1
盲目地覆蓋綁定上下文的ModelMetaData來設置模型的類型是否安全?我擔心可能會使用活頁夾在編輯場景中更新預建模型,如果我只覆蓋ModelMetaData,則會丟失數據。對IModelBinder.BindModel的調用是否已經設置了bindingContext.Model/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
有沒有一種方法,以確認ModelMetadata是同類型的那GetSpecificModelTypeBasedOnBindingData(BindingContext中)將返回,如果沒有拋出異常? –
你可以比較'bindingContext.ModelMetadata.ModelType == GetSpecificModelTypeBasedOnBindingData(bindingContext)',我想。 – HackedByChinese