Is there a way to create an ActionLink with HTML 5 Data- attributes?

后端 未结 2 814
[愿得一人]
[愿得一人] 2020-12-29 02:05

HTML5 allows the use of custom attributes prefixed with the phrase \"data-\" which pass validation without the use of a custom DTD (more info). In Asp.Net MVC, is there any

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 02:49

    Yes, there is an overload for ActionLink method which takes an IDictionary instead of an anonymous object.

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

    Outputs :

    text
    

提交回复
热议问题