Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC ModelMetadata - Do we violate separation of concerns when we put attributes to describe UI on model?

According to this blog post "ModelMetadata objects are constructed with data taken from attributes, primarily from the System.ComponentModel and System.ComponentModel.DataAnnotations namespaces."

By putting UI helper attributes on Model objects (DisplayFormat or UIHint) aren't we coupling Model and View?

like image 892
dev.e.loper Avatar asked Aug 17 '11 15:08

dev.e.loper


People also ask

What is separation of concerns in asp net asp net MVC?

Separation of concerns is a software architecture design pattern/principle for separating an application into distinct sections, so each section addresses a separate concern. At its essence, Separation of concerns is about order.

What are the advantages of MVC What do you mean by separation of concerns?

As per Wikipedia, "the process of breaking a computer program into distinct features that overlap in functionality as little as possible". The purpose of the MVC design pattern is to separate content from presentation and data-processing from content.

What is the principle of separation of concerns in c#?

In computer science, separation of concerns is a design principle for separating a computer program into distinct sections. Each section addresses a separate concern, a set of information that affects the code of a computer program.

What is Microsoft ASP net MVC 2?

The Model-View-Controller (MVC) pattern is an architectural design principle that separates the components of a Web application. This separation gives you more control over the individual parts of the application, which lets you more easily develop, modify, and test them. ASP.NET MVC is part of the ASP.NET framework.


1 Answers

I believe so. Personally I keep my model completely ui-agnostic and I write ViewModels which will represent my model in my View. Then assign all annotations to these ViewModels.

I think the violation comes from the fact that this limits your ability to reuse your model, since you are basically defining view behavior in your model.

like image 102
AJC Avatar answered Oct 11 '22 09:10

AJC