I have many widgets that can use JSON or JavaScript object literals as their data sources, and this data seldom changes, like the kendo menu below. This menu is hard-coded, and I’d prefer it stayed that way – I don’t want my app tp get too chatty just populating menus etc – but I’d like to emit that hard code from my Razor view.
$("#view-menu").kendoMenu({
dataSource: [
{
text: 'Save',
url: '#',
imageUrl: '@Url.Content("~/Content/Images/Save.png")'
},
{
text: 'Cancel',
url: '@Url.Action("Edit", "Employee", new {id = Model.EmployeeId})',
imageUrl: '@Url.Content("~/Content/Images/Cancel.png")'
}
]
});
$(".k-menu a.k-link[href=#]").click(function (e) {
e.preventDefault();
$(this).parents('form').first().submit();
});
Is there an existing helper I can use to e.g. render a KendoMenuConfig object that configures this menu? I would like something like this to replace the above:
$("#view-menu").kendoMenu({
@Html.KendoMenuConfig(blah blah))
});
No write your own html helper
return the string that correspond to your config and it will work, you are actually on the right way.
include the class that contains this extension in you /View/Web.config at the namespace part.