Setting LinkHtmlAttributes in Model Bound Menus

2 posts, 0 answers
  1. Drew
    Drew avatar
    3 posts
    Member since:
    Jun 2012

    Posted 26 Jul 2012 Link to this post

    I've got a menu bound to a model but I can't seem to set the LinkHtmlAttributes.

    It looks like this:


    @(Html.Kendo().Menu()
        .Name("menu")
        .BindTo(Model, mappings =>
            {
                mappings.For<MenuModel>(binding => binding
                    .ItemDataBound((items, menu) =>
                        {
                            items.Text = menu.Text;
    //I want to set the link attributes, but this isn't working
    items.LinkHtmlAttributes = new { foo = "bar" };
                        })
    )
  2. nikobellic
    nikobellic avatar
    46 posts
    Member since:
    Feb 2013

    Posted 11 Oct 2013 Link to this post

    You dont need to new up the Dictionary, just add elements to it. Like so:

    @(Html.Kendo().Menu()
        .Name("menu")
        .BindTo(Model, mappings =>
            {
                mappings.For<MenuModel>(binding => binding
                    .ItemDataBound((items, menu) =>
                        {
                            items.Text = menu.Text;
                //I want to set the link attributes, but this isn't working
                items.LinkHtmlAttributes.Add("data-foo", "bar");
                        })
        )
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top