将 CSS 应用到 Html.Action()
我正在使用 ASP.net MVC3,如何将 CSS 类添加到 @Html.Action()
。我已执行以下操作,但它不起作用:
@Html.Action("ProductEmailAFriendButton", "Catalog", new { productId = Model.Id, @class="test" })
I am working with ASP.net MVC3, how I can add a CSS class to an @Html.Action()
. I have done the following, but it isn't working:
@Html.Action("ProductEmailAFriendButton", "Catalog", new { productId = Model.Id, @class="test" })
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在第四个参数中提供类,即 htmlattributes,希望您能明白
provide the class in the 4th argument i.e. htmlattributes, hope you will get the idea
您确定不需要 ActionLink 吗? Action() 不能应用任何 Html 属性,因为它呈现您的操作并返回它的字符串表示形式。此外,您还在代码中混合了路由值和 HTML 属性。我认为以下是您正在寻找的内容。它将渲染一个指向操作的链接:
如果 Html.Action 是您想要的(即您想要将操作物理渲染为字符串)并且您想要将 CSS 类应用到渲染视图的父容器,那么您可以这样做类似于下面的内容:
Are you sure you don't want an ActionLink? Action() can't have any Html attributes applied to it since it renders your action and returns a string representation of it. Also, you are mixing route values and HTML attributes in your code. I think below is what you are looking for. It will render a link to an action:
If Html.Action is what you intended (i.e. you want to physically render the action to a string) and you want to apply a CSS class to the parent container of the rendered view then you could do something similar to below: