How to pass query string parameter in ActionLink in MVC

Solution 1:

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

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

These 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.

Solution 2:

Pass Query String By this way

@Html.ActionLink("Delete Record", "Home", "Delete", new { id=Id},null)

By above code you will get the url like(Suppose Id=1): /Home/Delete/1

and if you want to add more parameters to query string then:

@Html.ActionLink("Delete Record", "Home", "Delete", new { id=Id, Name=name},null)

By above code you will get the url like(Suppose Id=1 and Name=India) :

/Home/Delete/1?Name=India