Home > DeveloperSection > Forums > pass query string parameter in ActionLink in MVC
Alex Leblois
Alex Leblois

Total Post:67

Points:471
Posted on    October-17-2014 1:21 AM

 ASP.NET MVC ASP.NET MVC  Mvc4 
Ratings:


 1 Reply(s)
 3587  View(s)
Rate this:
I am having following action link:

   <%= Html.ActionLink("Check this", "Edit", "test", 
new { id = id}, new { style = "display:block" })%>

How to include "data=name" as query string. Some thing like link?data=name


Norman Reedus
Norman Reedus

Total Post:45

Points:315
Posted on    October-17-2014 1:22 AM

4th parameter of Html.ActionLink can have any number od properties:

   <%= Html.ActionLink("Check this", "Edit", "test", 
    new { id = id, data=name }, new { style = "display:block" })%>

Theese properties are inserted into URL based on routing, but if the property name cannot be matched into any route it is added as URL GET parameter. So if you have standard route "{controller}/{action}/{id}", you will get the URL test/Edit/[id]?data=[name] from the above code.

Don't want to miss updates? Please click the below button!

Follow MindStick