简体   繁体   中英

Apply CSS to Html.Action()

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" })
@Html.ActionLink("ProductEmailAFriendButton", "Catalog", new { productId = Model.Id},new{@class="test",@id="someid", @style="background:none #fff";})

提供第四个参数中的类,即 htmlattributes,希望你能明白

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:

@Html.ActionLink("ProductEmailAFriendButton", "Catalog", new { productId = Model.Id }, new { @class="test" })

If Html.Action is what you intended (ie 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:

<div class="test">@Html.Action("ProductEmailAFriendButton", "Catalog", new { productId = Model.Id })</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM