代码之家  ›  专栏  ›  技术社区  ›  AaronSieb

有没有办法用HTML5数据属性创建ActionLink?

  •  34
  • AaronSieb  · 技术社区  · 16 年前

    more info ). 在Asp.NETMVC中,是否有任何方法可以指定带有数据属性的ActionLink?

    向ActionLink添加属性的典型方法是传入一个匿名对象,每个对象都有一个自定义属性:

    new { customattribute="value" }
    

    new { data-customattribute="value" }
    

    2 回复  |  直到 16 年前
        1
  •  77
  •   Nadeem Khedr    15 年前

    或者你可以使用

    new { data_customattribute="value" }

    编译器足够聪明,能够理解你的意思

        2
  •  22
  •   Çağdaş Tekin    16 年前

    是的,有一个超负荷的 ActionLink 方法,该方法需要 IDictionary<string,object>

    <%=Html.ActionLink("text", "Index", "Home", null /*routeValues*/, 
        new Dictionary<string, object> { 
           { "data-customattribute", "value" }, 
           { "data-another", "another-value" } 
        })%>
    

    <a data-another="another-value" data-customattribute="value" href="/">text</a>
    
    推荐文章