First, configure the default routing method
{Controller=home}/{action=index}/{id?}
Default Request Address: Http://localhost:xxx/home/index
/ID? is an option such as
In HomeController
Public actionresult Index () { return Content ("OK"); } Public ActionResult Index (int ID) { return Content ("OK " ); }
The first method is the one that the default route points to.
The second method, the original request address should be: http://localhost:xxx/home/index?id=1, because/id, for the sake of can be changed to: HTTP://LOCALHOST:XXX/HOME/INDEX/1
Second, request parameter pass
1. Receive request parameters in the form of an object such as:
We have a class for receiving parameters
The corresponding method is as follows, plus [Frombody] 's purpose is to tell it to get the parameters in the body
Public class paramses{ publicstringgetset;} Public string Get Set ; } Public int Get Set ; }}
The parameter can be followed at the end of the address, or it can be an ajax JSON parameter such as:
Http://localhost:xxx/home/text?id=asdqwe&name=haos&age=1
$.ajax ({url:"", type:"Post",data:{ID:"qwe", Name:"ASD", age:1< c5>}})
2. Receive with parameter parameters of the object class
At this time the parameters are more flexible, can be arbitrary string;
Like what:
$.ajax ({url:"", type:"Post",data:{ID:"qwe", Name:"ASD", Age: 1 }})
What is received at this time
Then use the following method to convert to a dictionary to get the corresponding content
dictionary<stringstring> P = jsonconvert.deserializeobject<dictionary<string string>>(paramses. ToString ()); var i = p["ID"]; var int. Parse (p["Age"]);
. Net Core 2.0 Learning Routing and request parameter passing