Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想使用剃刀语法复制以下 html:
<a href="index.html" data-description="I Want This Description">Home</a>
我知道我会为链接这样做:
@Html.ActionLink("Home", "Index", "Home")
如何在 "data-description="I Want This Description"" 上方的 html 标记中添加信息?
您可以通过添加包含匿名对象的参数来添加 html 属性,该匿名对象包含您想要的属性和值。
@Html.ActionLink("Home", "Index", "Home", new { data_description = "I want this desription" })
注意下划线而不是连字符。显示视图时,MVC 会自动将下划线替换为连字符。