Using an interface as the model type of a partial view + data annotations

后端 未结 3 1219
北海茫月
北海茫月 2021-01-05 03:44

I have a case where a complex partial view needs different validation of fields depending on where the partial view is used.

I thought I could get around this by mak

3条回答
  •  [愿得一人]
    2021-01-05 04:12

    Well, actually you have a very reasonable idea! and can be archived is you use the non generic version of the HtmlHelper methods (ex. "@Html.Editor" instead of "@Html.EditorFor"), because the generic versions recreate the ModelMetadata (i don't know why!) based on the generic parameter type and don't use the ModelMetadata of the view. Freaking awful, isn't it?

    Hope this help.

提交回复
热议问题