MVC 3 Menu Navigation on from _layout page
I'm making the transition to MVC 3 and was attempting to create a friendly Menu Interface after the person logs onto the site. I stumbled across this article which suits what I need:
http://forums.asp.net/t/1583036.aspx/1
The third code sample is marvelous example of how I can dynamically build a menu interface. It contains the menu and the sub menu. The article creates a controller and a menu model, but I've struggled to get i开发者_开发知识库t implemented into Razor - has anyone successfully tried this route in a similar fashion?
Simply replace <%=
with @
:
@Html.MenuItem("Web Users", "Index", "Home")
In order to bring the MenuItem custom helper into scope for your Razor views make sure to reference it's namespace inside the <namespaces>
tag of ~/Views/web.config
(and not ~/web.config
):
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="SomeNamespace.Containing.The.Helper.Class" />
</namespaces>
</pages>
</system.web.webPages.razor>
精彩评论