1

I used to put the class of css in the action link like this:

<%: Html.ActionLink("Us", "Us", "Por", new { @class = "contactus" })%>

The purpose that I put the class is for the pop up of color box. Now I have an action in my controller that return the result to the view like this :

return Redirect(@"~/Test/TestFirst?msg=Please complete all the information.");

Question : How can I add class = "contactus" to the return of my action ?

Thanks in advanced.

1 Answer 1

2

The Controller cannot and should not add css classes, this is the views responsibility. And it looks like you are stuffing a message in the query string, but it probably should be in the TempData

Controller:

TempData["msg"] = "Please complete all the information";
return Redirect(@"~/Test/TestFirst");

View:

@if(TempData["msg"] != null)
{
  <div class="myclass">@TempData["msg"]</div>
}

notice that TempData will survive a redirect.

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

5 Comments

Thanks. But are there any solution to add the class to my link beside this?
@titi not from the controller
Thanks. But why don't you tell me the solution?
@titi I added some more details .. let me know if you need more help
@BassamMehanni +1 for pointing out that the view is responsible for rendering the page (client-side representation); separation of concerns is the whole point of the MVC paradigm

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.