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.
With this level of understanding, you will find that most of what you want in MVC can be obtained from ViewContext.
Reference Path: http://www.cnblogs.com/leo_wl/p/3504050.html
How ASP. NET MVC gets the value of the URL parameter in view