ASP.NET MVC:我为什么不能设置ShowForEdit模型的元数据属性? [英] ASP.NET MVC: Why can't I set ShowForEdit model metadata with an attribute?

查看:147
本文介绍了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:

<一个href=\"http://stackoverflow.com/questions/2959041/showing-different-fields-in-editorformodel-vs-displayformodel-modes-in-mvc2\">http://stackoverflow.com/questions/2959041/showing-different-fields-in-editorformodel-vs-displayformodel-modes-in-mvc2

这篇关于ASP.NET MVC:我为什么不能设置ShowForEdit模型的元数据属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆