If the URL is/home/index?id=3 direct request is OK.
But if the route is set to: {Controller}/{action}/{id}
URL is/HOME/INDEX/3
When I want to get the value of the parameter ID in Page view, how to get it?
I checked the information. Many people use the action to get the value of the parameter, and use ViewData to upload to the view
For example
The definition of phonelist in Controlers
Public ActionResult phonelist (int id)
{
viewdata["id"] = ID;
return View ();
}
In fact, it is not necessary, as long as it is obtained in view, it can:
<%=html.viewcontext.routedata.values["id"]%>
Even if the parameter without ID is not an error.
Same: <%=request.requestcontext.routedata.values["id"]%> and
<%=html.viewcontext.routedata.route.getroutedata (Html.ViewContext.HttpContext). values["id"]%>
can also be taken.
In a user control that is not directly accessible to Routedata,routedata is a property in the Page object,
Therefore, you need to use this in your user control. Page.routedata to get the parameters
Use this. page.routedata.values["id"] to get the value of the parameter
ASP. NET MVC gets the value of the URL parameter in view