简体   繁体   中英

@Html.RenderAction and CSS

How do I apply a class to the following so that I can apply a specific css style to it?

The rest of the consist of anchor tags so I can easily apply a class but where do I stick it on this @Html.RenderAction?????

<li>@{Html.RenderAction("CartSummary", "ShoppingCart");}</li>

RenderAction does not support passing in an object containing html attributes, like most other MVC helper methods do, so you cannot apply a css class directly using this method. Either you can wrap the output of RenderAction in a div with your css class from the parent view, or you can add a wrapper div to the output of the action itself.

RenderAction will output a PartialView so I guess your class attribute should be put in the view (the one you call from the method CartSummary in ShoppingCartController) or inside the <li> that call it (maybe with a DIV)

Why u don't want to use <a href="@Url.Action("index", "shoppingcart")" class="@yourClass" id="yourId">Cart (@ViewBag.CartCount)</a>

Be simple.

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