Search code examples
layoutasp.net-mvc-3razorasp.net-mvc-controller

MVC 3 Layout and Controllers


I m building a MVC 3 applications. The application should be able to display a different layout according to the sub domaine (ex: customer1.mysite.com -> layout1; customer2.mysite.com -> layout2; etc...) it will have also a layout for mobile and IE 6.

I have seen that their is the _ViewStart.cshtml that I can leverage to do the logic to set the layout. But what I don't get is where is the controler for that? Should I write all the code in the view?

An other question with layout how to do you factor out the code for the common behaviours? Do you have a controler for that?

And a last one I have seen the concept of areas in asp.net MVC2 is it obsolete now that we have Razor?

Thank you for your help

Fred


Solution

  • While you could do this in the _ViewStart I think that a better way would be to write a custom view engine in which based on the user agent or the domain include a different layout. Then you would have common controllers and views, only the layout will differ.