Rendering MVC menu on partial view

2 posts, 0 answers
  1. Phil
    Phil avatar
    15 posts
    Member since:
    Oct 2012

    Posted 22 Feb 2013 Link to this post

    Apologies if this has been answered somewhere (couldn't find anything though)...

    I have an MVC4 project and I'm using the MVC controls to add a menu to the page from a partial view.

    On the _Layout.cshtml file I have:
    <div id="navigation">
        @Html.Action("Navigation", "Core")
    </div>
    And then in the Navigation.cshtml file I have:
    @{
        Html.Kendo().Menu().Name("menu").Items(menu => {
            menu.Add().Text("Home").Action("Index", "Home");
            menu.Add().Text("ACH Entry").Action("ACHEntry", "Home");
            menu.Add().Text("CC Entry").Action("CCEntry", "Home");
            menu.Add().Text("ACH and CC Search").Action("ACHCCSearch", "Home");
            menu.Add().Text("ACH and CC Edit").Action("ACHCCEdit", "Home");
            menu.Add().Text("ACH Processing").Action("ACHProcessing", "Home");
            menu.Add().Text("CC Processing").Action("CCProcessing", "Home");
            menu.Add().Text("ACH and CC On-Hold Report").Action("ACHCCOnHoldReport", "Home");
            menu.Add().Text("ACH and CC Activity Search").Action("ACHCCActivitySearch", "Home");
            menu.Add().Text("Generate DDA File List").Action("GenerateDDAFileList", "Home");
            menu.Add().Text("Series End Report").Action("SeriesEndReport", "Home"); }).Orientation(MenuOrientation.Vertical));
    }
    (Sorry for squishing it together.  The debugger threw exceptions when I had items on different lines, too).

    However, I get a very non-descript error message whining about a missing semicolon, when this would work fine on the _Layout.cshtml page.  I really don't want to put it there unless I have no other choice.  There error is:

    HttpException:

       Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.

    The inner exception reveals:

       Navigation.cshtml(15): error CS1002: ; expected"

    But none of that would happen on the _Layout.cshtml page.
    Thoughts?
  2. Phil
    Phil avatar
    15 posts
    Member since:
    Oct 2012

    Posted 22 Feb 2013 Link to this post

    This is weird, but it works:

    @(
        Html.Kendo().Menu().Name("menu")
            .Items(items => {
                items.Add().Text("Home").Action("Index", "Home");
                items.Add().Text("ACH Entry").Action("ACHEntry", "Home");
                items.Add().Text("CC Entry").Action("CCEntry", "Home");
                items.Add().Text("ACH and CC Search").Action("ACHCCSearch", "Home");
                items.Add().Text("ACH and CC Edit").Action("ACHCCEdit", "Home");
                items.Add().Text("ACH Processing").Action("ACHProcessing", "Home");
                items.Add().Text("CC Processing").Action("CCProcessing", "Home");
                items.Add().Text("ACH and CC On-Hold Report").Action("ACHCCOnHoldReport", "Home");
                items.Add().Text("ACH and CC Activity Search").Action("ACHCCActivitySearch", "Home");
                items.Add().Text("Generate DDA File List").Action("GenerateDDAFileList", "Home");
                items.Add().Text("Series End Report").Action("SeriesEndReport", "Home"); })
            .Orientation(MenuOrientation.Vertical))
    Found this from this thread: http://www.kendoui.com/forums/ui/menu/create-a-menu.aspx

    Which lead me to: http://weblogs.asp.net/scottgu/archive/2010/12/16/asp-net-mvc-3-implicit-and-explicit-code-nuggets-with-razor.aspx

    Which suggested the use of "@()"
  3. Kendo UI is VS 2017 Ready
Back to Top