有没有办法用HTML 5数据 - 属性创建ActionLink的? [英] Is there a way to create an ActionLink with HTML 5 Data- attributes?
问题描述
HTML5允许使用的自定义属性的短语pfixed $ P $数据 - ,它通过验证,而无需使用自定义DTD(中的更多信息)。在Asp.Net MVC中,有没有办法用一个数据 - 属性指定ActionLink的?
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 way to specify an ActionLink with a data- attribute?
添加属性的ActionLink的典型方法是在一个匿名对象传递,以及每个对象的自定义属性:
The typical method for adding attributes to an ActionLink is to pass in an anonymous object, with a custom property for each object:
new { customattribute="value" }
我想要做的是:
new { data-customattribute="value" }
但是,这并不工作,因为连字符是不是在属性名有效。有没有解决这个限制什么办法?或者,我只是用ActionLinks,并使用数据 - 属性之间做出选择?
But this doesn't work, because the hyphen character isn't valid in property names. Is there any way around this restriction? Or do I just have to choose between using ActionLinks and using data- attributes?
推荐答案
也可以使用
新{data_customattribute =值}
和编译器是足够聪明,知道你的意思。
and the compiler is smart enough to know what you mean
这篇关于有没有办法用HTML 5数据 - 属性创建ActionLink的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!