开发者

ASP.NET MVC 3 Display Annotations - Why in Model?

Why are the ASP.Net MVC 3 display annotations in the model? Isn't the View responsible for the display?

Of course, I'm not arguing with the ASP.NET MVC design team, but I'm trying to check my understanding.

If indeed th开发者_如何学Gois is a violoation of the separation of concern, is there an alternative way which avoids this?

edit: I'm refering to annotations such as DataType, DisplayName and DisplayFormat. I'm now viewing a PluralSight (excellent) lecture, and they're putting those attributes on the model.


Why are the ASP.Net MVC 3 display annotations in the model?

Data Annotations shouldn't be placed on the Model. They should be on the VIEW MODEL which is fundamentally different and is what controllers pass to the views. Especially those that are related to formatting. Because view models are tightly coupled to a specific view there are no problems.

IMHO if an application uses Data Annotation attributes such as DataType, DisplayName and DisplayFormat on the model then I wouldn't recommend you using this application as an example of good practices.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜