In my mvc web application I want to generate dynamic menu. I want to generate it only first time when a user get log in but not every time when a user go to another view. I want to put menu generated code in layout cstml. But as I know layout refresh each time. Is there any way to solve the issue. Please help me. I am new in mvc. advance thanks to all.
Asked
Active
Viewed 8,021 times
-1
-
No you can't do like that. Better cache the menu items in temp storage like session/cache and construct it – Murali Murugesan May 27 '14 at 09:41
3 Answers
2
You need to put the content of the page in ajax div. Then, each time update the div only.

jinxinhelloworld
- 97
- 2
- 8
1
You can check the condition in the each view where you do not want to load the layout.cshtml page.
MVC 3: How to render a view without its layout page when loaded via ajax?
otherwise you can also set another layout view where menu control is not there and check if first time user logged in then load menu layout else another layout.
-
I want to put menu in layout. When I click another page using menu item the layout will remain same but the corresponding page will be loaded. – Shariful_Islam May 27 '14 at 10:21
-
use another layout and apply that new layout in your corresponding pages, @{ Layout = "~/Views/Home/newLayout.cshtml"; } – Brijesh May 27 '14 at 11:56
0
just insert
@{
Layout = null;
}
on top in your view where you do not want layout

rjdmello
- 865
- 2
- 9
- 14
-
If I put layout=null then how I get the menu? Because I want to put menu in layout. – Shariful_Islam May 27 '14 at 10:19
-
I want to put menu in layout. When I click another page using menu item the layout will remain same but the corresponding page will be loaded. – Shariful_Islam May 27 '14 at 10:22
-
so you want SPA then you need to use knockout or angularjs http://msdn.microsoft.com/en-us/magazine/dn463786.aspx – rjdmello May 27 '14 at 10:27
-
in this mvc you and insert partial view in different div and hide that div and on click of specific menu show that div – rjdmello May 27 '14 at 10:29
-
This answer is valid by itself. if you want to exclude the base layout and make your own page with different html structure. It worked in my case. – Zahari Kitanov Nov 03 '19 at 12:29