Reputation: 263
When I generate my hyperlink dynamically then I get a question mark added in the URL where does it comes from what is the meaning of it.
<li> @Html.ActionLink(@genre.Name, "Browse", new { genre = genre.Name })</li>
http://localhost:26239/Store/Browse?genre=Disco
Upvotes: 0
Views: 3323
Reputation: 3217
There is typical example. We have one route for BookDetail:
routes.MapRoute(
name: "BookDetail",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Book", action = "Detail", id = UrlParameter.Optional }
);
First example - with one parameter id
defined in route rule
<li>@Html.ActionLink(@item.Name, "Detail", new { id = item.Id })</li>
http://localhost:26239/Book/Detail/221
Second example - with another parameter xy
not defined in route
<li>@Html.ActionLink(@item.Name, "Detail", new { id = item.Id, xy = item.Xy })</li>
http://localhost:26239/Book/Detail/221?xy=SomeValue
Third example - without parameters (because id
is optional)
<li>@Html.ActionLink(@item.Name, "Detail")</li>
http://localhost:26239/Book/Detail
Upvotes: 2
Reputation: 8513
If "genre" is not defined in the route that matches the action method as a parameter, it will be passed as query string.
Upvotes: 2
Reputation: 17690
That's called a query parameter. It's a very common way to pass variables in the URL.
Upvotes: 1