Action parameters appearing in the query string instead of the URL

I'm doing it:

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

The URLs are as follows: / MyController / Details? id = 1

How can I format it, for example: / MyController / Details / 1

Routes are as follows:

 routes.MapRoute("Default", "{Controller}/{Action}", new { Controller = "Home", Action = "Index" }); routes.MapRoute("Default-ID", "{Controller}/{Action}/{ID}"); 
+6
source share
1 answer

The order of the routes matters - both URLs are valid, and in this case, the system first receives a query string when it searches for the URL corresponding to this action.

Also, you have a case sensitivity problem with {ID} - not sure about this, but it is usually best to use the case sequentially.

+8
source

Source: https://habr.com/ru/post/890564/


All Articles