ASP.NET MVC: Use Html.ActionLink and add route values / HTML attributes to it

If you render a Link to another Controller / View, you can just use the method 'Html.ActionLink' on a view. If you want to submit additional parameters / action parameters in the link, you can use the overloads of 'Html.ActionLink'.

11 January 2011
Christoph Keller Christoph Keller

If you render a Link to another Controller / View, you can just use the method 'Html.ActionLink' on a view:

Html.ActionLink("Link Title", "TargetAction", "TargetController");

Now, if you want to submit additional parameters / action parameters in the link, you can use the overloads of 'Html.ActionLink':

Html.ActionLink("Link Title", "TargetAction", "TargetController", new { id = 1 }, new { title = "My link to TargetController, class = "linkClass" })

As you can see, the action 'TargetAction' will receive a parameter 'id' with the value of '1'. To the 'a href' HTML tag, a title and the CSS class "linkClass" will be rendered.

According the MSDN (http://msdn.microsoft.com/en-US/library/dd504972.aspx) the key/value pairs will be retreived through reflection by examining the properties of the object.

 ASP.NET  MVC  Render 

comments powered by Disqus