首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ActionLink htmlAttributes

ActionLink htmlAttributes
EN

Stack Overflow用户
提问于 2010-11-06 02:32:34
回答 3查看 149.2K关注 0票数 89

作品

<a href="@Url.Action("edit", "markets", new { id = 1 })" 
            data-rel="dialog" data-transition="pop" data-icon="gear" class="ui-btn-right">Edit</a>

不工作-为什么?

@Html.ActionLink("Edit", "edit", "markets", new { id = 1 }, new {@class="ui-btn-right", data-icon="gear"})

看起来你不能把像data-icon="gear“这样的东西传递给htmlAttributes?

有什么建议吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-11-06 06:35:15

问题是您的匿名对象属性data-icon的名称无效。C#属性的名称中不能有短划线。有两种方法可以解决这个问题:

使用下划线而不是破折号(MVC会自动将发出的HTML中的下划线替换为破折号):

@Html.ActionLink("Edit", "edit", "markets",
      new { id = 1 },
      new {@class="ui-btn-right", data_icon="gear"})

使用接受字典的重载:

@Html.ActionLink("Edit", "edit", "markets",
      new { id = 1 },
      new Dictionary<string, object> { { "class", "ui-btn-right" }, { "data-icon", "gear" } });
票数 206
EN

Stack Overflow用户

发布于 2011-12-22 14:50:52

将所需的连字符替换为下划线;它将自动呈现为连字符:

@Html.ActionLink("Edit", "edit", "markets",
    new { id = 1 },
    new {@class="ui-btn-right", data_icon="gear"})

变成:

<form action="markets/Edit/1" class="ui-btn-right" data-icon="gear" .../>
票数 26
EN

Stack Overflow用户

发布于 2016-08-18 15:12:54

@Html.ActionLink("display name", "action", "Contorller"
    new { id = 1 },Html Attribute=new {Attribute1="value"})
票数 -6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4108943

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档