Reputation: 1114
First of all, I still learning ASP MVC.
we all know the default setup in url is controller/action/id
Yet when submitting a form, model is what we pass into controllers, which contain all the data we want, so what's the point of passing id in the url? in which case do we need id?
Until now the only way id can be used is get the model from EF.
Upvotes: 0
Views: 103
Reputation: 3204
Routing mechanism in ASP.NET MVC is, partly, based on Resource-oriented architecture (ROA). In this way a URI is responsible to identify a unique resource in the web, the ID that you have mentioned in your question is the identity of the specific resource in your website.
Obviously, it is used for retrieving (GET) information.
Upvotes: 0
Reputation: 1166
The Id is typically used as part of GET requests to identify a particular resource. Look at the querystring for this site. Their url is configured slightly differently, but there is an id in there and for your question it is "18127537".
The other part of your question is related to POST requests in which the model is created and passed to your controller action method.
Upvotes: 2
Reputation: 17307
Until now the only way id can be used is get the model from EF.
Yes, exactly. The purpose is for your GETs. /Foo/Items/1
is a much cleaner Url than Foo/Items?id=1
. It doesn't do anything for you on a POST.
However, it is entirely up to you what your Urls look like. Feel free to change it to whatever you want.
Upvotes: 2