ASP.NET MVC:我为什么不能设置ShowForEdit模型的元数据属性?

问题描述:

我为什么不能设置 ShowForEdit 与属性模型元数据?

Why can't I set ShowForEdit model metadata with an attribute?

似乎提供的唯一属性来改变这是 [ScaffoldColumn] 设置,使 ShowForEdit ShowForDisplay ,这是不是我想做的事情。我希望能够从我的模型分别标注两个。

It seems that the only attribute provided to alter this is [ScaffoldColumn], which sets both ShowForEdit and ShowForDisplay, which is not what I want to do. I want to be able to annotate the two separately from on my model.

由于它不支持开箱即用。据我所知的原因是因为dataannotations属性支持此功能是在.NET 4.0中,为了使MVC 3.5和4.0兼容,他们已被排除。

Because it is not supported out of the box. AFAIK the reason is because the dataannotations attribute that support this functionality are in .net 4.0 and in order to make MVC 3.5 and 4.0 compatible they had to be excluded.

解决这个问题的最简单的方法就是要实现自己的编辑/查看属性,如本问题/答案证明:

The easiest way to fix this is to have to implement your own Edit/Show attribute as demonstrated in this Question/Answer:

http://*.com/questions/2959041/showing-different-fields-in-editorformodel-vs-displayformodel-modes-in-mvc2