c# - How could i change layout page from viewpage in mvc -


I am working with razor at asp.net mvc 3. My project has a layout (Master) page with a link to 4 side and a side panel for the watch page (@RenderBody). When the user clicks on link 1, redirect 1 and link 1 should be selected to see it, and when he clicks on link 2, it is redirected to see page 2 and link 2 so Should be chosen. It redirects to the required pages very well but it only selects 1 link, although I clicked on link 2, link 3, link 4. How do I choose the appropriate link from the Personal View page to the layout page? guide me. Selected I think that you highlights using CSS

Em>, do not you? If this is the case, then I propose to write a custom HTML helper to make those links:

  public static IHtmlString MenuItem (this HtmlHelper html helper, string text, string action, string Controller) {var Li = New Tag Builder ("Lee"); Var pathData = htmlHelper.ViewContext.RouteData; Var current action = Margaata.Getreified string ("Action"); Var current controller = route data Gettyfitted string ("controller"); If (String .Elloles (Current Action, Action, String Comparison, Ordinal Ignore Seas) and String .Elloles (Current Controller, Controller, String Compiler, Ordinal Ignition Case)) {li.AddCssClass ("Active"); } Li.InnerHtml = htmlHelper.ActionLink (text, action, controller). ToHtmlString (); Return the new HTML string (li.ToString ()); }   

and then use the assistant inside your layout:

  & lt; Ul & gt; @html Menu ("Link 1", "Action 1", "Controller 1") @html Menu ("Link 2", "Action 2", "Controller 2") ... & lt; / Ul & gt;   

And now what is left is to define the .active rule in its CSS class:

  There is some spec for populating the currently selected link from Active {.    

Comments