I am trying to send the route values to a method but I cant seem to figure this out. Here is my code
<% string s = "cool";
object d = new { s = "1" };
%>
<%= Html.ActionLink("Home", "Index", d, "ql")%>
The following code produces a url like this
http://localhost:49450/?s=1
the url should be like this
http://localhost:49450/?cool=1
What am I missing
because in the context of a ‘new { … }’ expression the ‘s’ does not correspond to a variable as it may first appear – it defines the name of a member of an anonymous class that is created.
when you say :
new { S = 123 }
you are actually generating a class, which is anonymous (you never get to see the name of the class). The type of each member of the class is implicitly determined by whatever you’re assigning to it. In the above example a class something like this is generated
There are two ways you can do what you want:
1) you would have to say :
2)
Now I assume though that you want the name to be dynamic so you need to use RouteValueDictionary which allows you to put key value pairs in.
As you can see, here you can use a variable ‘s’ to represent whatever you want. This should give you the URL you need.