Omer
Omer

Reputation: 10194

What is the special meaning of id in MVC

As you know when we want to go details of an item it is achieved by

@Html.ActionLink("Details", "Details", new { id=item.Id })

http://localhost:xxxx/Item/Details/1

What should we call this "1" parameter? It is not a querystring parameter but what is it? Does mvc interpret this parameter as a querystring parameter?

And another thing is, when I set the link as below:

@Html.ActionLink("Edit", "Edit", new { itemIdNo=item.Id })

mvc creates this link as:

http://localhost:xxxx/Item/Details?itemIdNo=1

As you see, they are quite different. Does "id" parameter have special meaning in MVC?

What should we call this "1" parameter? It is not a querystring parameter but what is it?

Does mvc interpret this parameter as a querystring parameter?

Upvotes: 1

Views: 672

Answers (2)

kkakkurt
kkakkurt

Reputation: 2800

In your RouteConfig.cs, it adjusted as "id":

routes.MapRoute(
               name: "Default",
               url: "{controller}/{action}/{id}",
               defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

If you want to change it, you can change {id} parameter as {itemIdNo}. And also idparameter in "defaults:" line as itemIdNo.

Upvotes: 4

Daniel Abbatt
Daniel Abbatt

Reputation: 145

It's a url path parameter. The name id is used to match against a parameter on the controller action with the same name. You could use any name you, like you have in the second example. You can specify in route actions where the value id should come from, the body, url etc

Upvotes: 2

Related Questions