0

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" })
1
  • 5
    @Html.Action renders a child action not a hyperlink. You need to use @Html.ActionLink to generate a hyperlink Commented Sep 10, 2011 at 15:29

2 Answers 2

5
@Html.ActionLink("ProductEmailAFriendButton", "Catalog", new { productId = Model.Id},new{@class="test",@id="someid", @style="background:none #fff";})

provide the class in the 4th argument i.e. htmlattributes, hope you will get the idea

Sign up to request clarification or add additional context in comments.

Comments

2

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 (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:

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

1 Comment

Thanks Ryan. You are right ! Html.Action() can't have CSS applied to it ! Here's what it was giving me: i52.tinypic.com/11w3eh2.jpg Html.Action was getting a PartialView. I needed to get to the Partial View and change things there. Thanks so much for the help. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.