viewstate - Menu State - ASP.Net MVC -


In my asp.net mvc view, I have a menu that contains many items in the menu, including the hair item (anchor tag) ).

I am using JQuery to turn the menu item on and off, as the user clicks on them.

Unfortunately, once the user clicks the anchor tag, and gets sent to another page, the menu state is lost, and the menu goes back to the close.

Now if I had "normal" ASP.NET, I paste the menu state information in the viewstoat, and am storing information like that

Do something similar to MVC possible ?? This is the first MVC project I have worked on, so be gentle with me!

Then let me first make sure that I understand you correctly.

The user will click on a menu, which will take them to another page. And when he goes to that page, you want to reflect the fact that he is on that page? correct?

It does not seem very difficult. I think the menu is a partial view - so you'll present it something like this:

   

Then the scene will already know which menu object triggered it. For example, if the user clicks on the widget-> New, then you return the NewWidget.aspx view , And it will know that Widget-> New to highlight menu items. So you can use only to highlight the name or id of the menu item.

  & lt; Div id = "menu" & gt; & Lt;% HTML; Render Partial ("Menu", "Nudrite Link"); & Gt%; & Lt; / Div & gt;  

If this is not the case that a scene already knows which menu item is highlighted, then you have to pass the ID of the menu item with the link. Your link generation will look something like this:

  html.ActionLink ("menu item text", "controller's name goes here", "action name goes here", new { MenuItem = "menuItemId goes here"}, blank)  

Then your operation must handle this parameter. Take the easiest parameters and add it to the vendetta. The menu will then examine to highlight the menu item in ViewData.


Comments