This is a migrated thread and some comments may be shown as answers.

Rendering MVC menu on partial view

1 Answer 193 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 22 Feb 2013, 03:49 PM
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?

1 Answer, 1 is accepted

Sort by
0
Phil
Top achievements
Rank 1
answered on 22 Feb 2013, 04:05 PM
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 "@()"
Tags
Menu
Asked by
Phil
Top achievements
Rank 1
Answers by
Phil
Top achievements
Rank 1
Share this question
or