Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET MVC > General Discussions > Binding to MVC menu with a template issue

Not answered Binding to MVC menu with a template issue

Feed from this thread
  • kris avatar

    Posted on Feb 2, 2012 (permalink)

                                                     I would like to override the ActionLink default menu item. I've tried the following code (and would actually like to use the commented out part) to no avail.
    I got past duplicate variable compile errors (there is another menu in the master page) by changing the linq variable names.
    Now I get nothing displayed at all. All of the examples I have seen manually add the menu items to the menu, none of the examples have the ItemDataBound.
    Please help me understand what I am doing wrong. Thanks

    @(Html.Telerik().Menu()
                .Name("Menu")
                .BindTo(Model.MenuItems, mappings =>
                {
                    mappings.For<ExplorerToolbarDataViewModel>(binding => binding
                    .ItemDataBound((explorerItem, explorerMenuItem) =>
                    {
                        explorerItem.Content = () =>
                                                   {
                                                       MvcHtmlString.Create(string.Format("<input type='image' src="~/Content/images/toolbar-placeholder.gif" value='{0}' id='{1}' class='{2}' onclick=\"$('#{3}').val('{4}')\" />",
                                                           explorerMenuItem.Name,
                                                           explorerMenuItem.Id,
                                                           explorerMenuItem.LinkHtmlAttributes.FirstOrDefault(a => a.Key == "class"),
                                                           explorerMenuItem.UpdateTargetId,
                                                           explorerMenuItem.Command));
                                                   };
                    }));
                }))
            @*<input type='image' value='@explorerMenuItem.Name' id='@explorerMenuItem.Id' class='@explorerMenuItem.LinkHtmlAttributes.FirstOrDefault(a => a.Key == "class")' onclick="$('#@explorerMenuItem.UpdateTargetId').val('@explorerMenuItem.Command')" />*@
          
            @Html.HiddenFor(m => m.Command, new { id = "cmc_explorer_toolbar_command" })
            @Html.HiddenFor(m => m.ExplorerPath, new { id = "cmc_explorer_toolbar_path" })
            @Html.HiddenFor(m => m.ExplorerType, new { id = "cmc_explorer_toolbar_type" })
     


    public class ExplorerToolbarViewModel : ToolbarViewModel
        {
            public ExplorerToolbarViewModel()
            {
                this.MenuItems = new Collection<ExplorerToolbarDataViewModel>();
            }
     
            public new Collection<ExplorerToolbarDataViewModel> MenuItems { get; set; }
     
            public string ExplorerPath { get; set; }
     
            public string Command { get; set; }
     
            public ExplorerObjectType ExplorerType { get; set; }
        }

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET MVC > General Discussions > Binding to MVC menu with a template issue