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" })
@(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" })
@(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));
};
}));
}))
@*<
'@explorerMenuItem.Name'
'@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; } }
public class ExplorerToolbarViewModel : ToolbarViewModel
public ExplorerToolbarViewModel()
this.MenuItems = new Collection<
>();
}
public new Collection<
> MenuItems { get; set; }
public string ExplorerPath { get; set; }
public string Command { get; set; }
public ExplorerObjectType ExplorerType { get; set; }
Reply
Back to Top
UI controls for ASP.NET AJAX, MVC, WPF, Silverlight, Windows Forms and Windows Phone. Visual Studio productivity tools. Reporting and data layer solutions.
HTML5 / JavaScript tools for Web and Mobile applications
Functional, Performance, Load and Mobile Software Testing
CMS, Mobile Web, Ecommerce, Emarketing, Social Media
Project management software inspired by Agile best practices
It seems you haven't bookmarked any pages. Fix that by clicking the button below