javascript - Regarding multiple master pages in mvc4 -
i have 1 master page named site.master in have tabs logic
<div id="menubar"> @html.simplenav(new[] { new simplenavitem{text="home", action="index", controller = "home",getselected = ((a, c) => (c == "home" && == "index"))}, new simplenavitem{text="blog", action="index", controller = "blog", getselected = ((a, c) => (c == "blog" && == "index"))}, new simplenavitem{text="about", action="about", controller = "home", getselected = ((a, c) => c == "home" && == "about")}, new simplenavitem{text="contact", action="contact", controller = "home", getselected = ((a, c) => c == "home" && == "contact")} }) %> </div> tab logic class file code
public static class simplenavextensions { public static string simplenav(this htmlhelper html, ienumerable<simplenavitem> navitems) { var urlhelper = new urlhelper(html.viewcontext.requestcontext); string controller = html.viewcontext.routedata.values["controller"].tostring(); string action = html.viewcontext.routedata.values["action"].tostring(); tagbuilder ul = new tagbuilder("ul"); ul.addcssclass("clearfix"); stringbuilder listbuilder = new stringbuilder(); tagbuilder li = null; tagbuilder = null; foreach (var item in navitems) { = new tagbuilder("a"); a.attributes.add("href", urlhelper.action(item.action, item.controller)); a.innerhtml = item.text; li = new tagbuilder("li"); if (item.getselected != null && item.getselected(action, controller)) li.addcssclass("sel"); li.innerhtml = a.tostring(); listbuilder.append(li.tostring()); } ul.innerhtml = listbuilder.tostring(); return ul.tostring(); } } public class simplenavitem { public string text { get; set; } public string action { get; set; } public string controller { get; set; } public func<string, string, bool> getselected { get; set; } } now 3 other page inherit site.master example about.aspx
<%@ page title="" language="c#" masterpagefile="~/views/shared/site.master" inherits="system.web.mvc.viewpage<dynamic>" %> <asp:content id="content1" contentplaceholderid="titlecontent" runat="server">about</asp:content> <asp:content id="content2" contentplaceholderid="maincontent" runat="server"> <h2>about</h2> </asp:content> now have master page named main.master want site.master should inherit main.master page..so should
Comments
Post a Comment