1

How could I dynamically change the css of a actionLink control on CSHTML page. Suppose, I am getting a "type" parameter on the CSHTML page and on this "type" parameter basis I want to change the css of "ActionLink" on a CSHTML page. Please suggest.

2 Answers 2

3

Try This :

if(type == "somevalue")
{
  @Html.ActionLink("click here","index","Home", null ,new{ @class="myclass" })
}
else
{
  @Html.ActionLink("click here","index","Home", null ,new{ @class="otherclass" })
}

OR

@Html.ActionLink("click here","index","Home", null ,new{ @class = (type == "somevalue" ? "myclass" : "otherclass") })
Sign up to request clarification or add additional context in comments.

Comments

1

Try

Html.ActionLink("Home", "", "", null, (ViewBag.type == "your type") ? new { @class = "typeclass" } : new { @class = "otherclass" })

Comments

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.