Has Microsoft changed the way a string is passed as a parameter in ASP.NET MVC 3?

I have this simple question. Previously, when I wanted to call a controller method with only one parameter, I could just call it /ControllerName/Method/Parameterany type of parameter. Now I did the same with the integer value without any problems, but with the string this did not work. Am I going to go crazy or has Microsoft really changed that?

+3
source share
2 answers

The default route that you find in Global.aspx.cs still looks like this:

routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
);

, "" - {id} , , , , . , ! : http://www.asp.net/mvc/tutorials/asp-net-mvc-routing-overview-cs

0

, , int, :

public ActionResult Index(int id)

( ), id , :

public ActionResult Index(string id)

:

public ActionResult Post(string slug)

, querystring (get) form (post) slug. , slug, BlogController), :

routes.MapRoute(
    "BlogPost",                                             
    "post/{slug}",                           
    new { controller = "Blog", action = "Post", slug = "" }  
);
0

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


All Articles