Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have just seen a video about ASP.NET MVC and the developer in that video was kind of mixing the HTML with C# or MVC markup. So, how can I hear people talking about sepration in MVC and I saw a mix! Could any anyone clarify for me this point?

share|improve this question
I think you should consider embracing ASP.NET MVC for awhile, write some code, and then decide whether or not it is a good approach to web development. I think you will find that a lot of your questions like this one will be answered if you do that, because you will have a better working understanding of the framework. No web development framework is perfect, but ASP.NET MVC does a pretty good job at separating concerns and promoting a sensible approach to application organization. – Robert Harvey Jul 6 '11 at 16:54
This blog post by Rob Conery may be of interest: ASP.NET MVC: Avoiding Tag Soup – Carson63000 Jul 6 '11 at 23:34

3 Answers

The mix is supposed to be minimal. You should write code only for getting values out of variables passed to the view, or calling functions that would "render" form elements, etc. I suppose you could add non-trivial code in there, but you should move all the complex processing to the controller.

share|improve this answer

MVC Still renders as HTML. If you want to create a robust custom control dynamically at runtime then there will be some logic around that creation. But the data layer should be seperate from the view.

share|improve this answer

The view (.cshtml and .aspx) files are OK if they contain code. However, that code should be specific to data display and not to data processing. The view should only know how to display the expected viewmodel/model that it is given and should not do calculations, persistence, or anything else that is not directly related to "prettifying" the data for the viewing pleasure of the user. The closest thing to business logic that you should have in the view is client side validation code that may be necessary to reduce server trips.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.