Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action parameters showing up in querystring instead of URL

I'm doing this:

@Url.Action("Details", "MyController", new { id = this.Model.ID })

The URLcomes out like this: /MyController/Details?id=1

How do I get it to format the URL like this: /MyController/Details/1

The routes look like this:

routes.MapRoute("Default", "{Controller}/{Action}", new { Controller = "Home", Action = "Index" });
routes.MapRoute("Default-ID", "{Controller}/{Action}/{ID}");
like image 218
Josh M. Avatar asked Jun 15 '11 02:06

Josh M.


People also ask

How do I pass parameters to URL?

Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&".

What is Querystring in URL?

A query string is the portion of a URL where data is passed to a web application and/or back-end database. The reason we need query strings is that the HTTP protocol is stateless by design. For a website to be anything more than a brochure, you need to maintain state (store data).

Can we send URL parameters in POST request?

In a GET request, the parameters are sent as part of the URL. In a POST request, the parameters are sent as a body of the request, after the headers. To do a POST with HttpURLConnection, you need to write the parameters to the connection after you have opened the connection.

How do you pass parameters in Querystring?

To pass in parameter values, simply append them to the query string at the end of the base URL. In the above example, the view parameter script name is viewParameter1.


1 Answers

The order of routes matters - both urls are valid, and in this case the system gets to the query string one first when looking for a url matching that action.

There's also a possibility you have a case sensitivity issue with {ID} - not sure about that one, but generally it is best to use case consistently.

like image 63
Tom Clarkson Avatar answered Sep 20 '22 03:09

Tom Clarkson