Home  /  Questions  /  Question

55   94.7
Jul 21, 2011

MVC 3 + Razor + Areas (Cannot call layout page)

Hi Team,

Can any one had experience with MVC 3+ Razor + Areas?
I do not get the layout page when I access Areas view pages.. Can anyone help me in this?
I am good with routing and I can access view page inside Areas but it is not showing the ayout page (Masterpage)


830   99.9
Jul 22, 2011

Here is what you need:  Include the _ViewStart.cshtml file in the Views folder for the Area.
In fact, if you have a global layout, you should add this file to each Area.

Hope this helps.


1,364   100.0
Jul 23, 2011
 1 comment
Hi Thanks for this link, but using this link I have had Go to Home link for all the pages using partialrender Menu.cshtml still I had issue with my master layout is not calling Area view . If you have any sample code for using both Area and Initial login. Initial login is coming correctly when I will click area view link clik that time master layout disapprearing. Thanks. --- Arul Kalivarathan  Jul 25, 2011

588   99.9
Jul 24, 2011
Do as Dan suggests and also add your own _layout.cshtml file.  If you have different Areas that will display content differently, it's good to have one _layout.cshtml for each Area.

Also, if you are using VS 2010, you should definitely make sure you are using the latest Tools Update for Visual Studio.  This changes the "Add" dialogs to include many new features including HTML5 stuff.

I hope this helps.
 1 comment
Hi Thanks for your reply, do you have any sample code for the above example, it would be more helpfull for me. my id is arulkg@yahoo.com , thanks for your help. --- Arul Kalivarathan  Jul 25, 2011

108   96.7
Nov 21, 2012
I added the _ViewStart.cshtml to the areas but the problem it is now causing me is that my page loads twice. So I have index method which gets called initially and populates a grid with a blank object.I also have Index with a parameter that gets called when a button is clicked. When I click the button the Index(int param) gets called but then the _ViewStart also appears to get called and loads the Index() method and clears out my data. If I remove the _Viewstart.cshtml it appears to work but now I have no formatting/layout to my page. I experienced this before and can't remember how I fixed it.

asp.net mvc 4