ASP. NET MVC gets the value of the URL parameter in view

Source: Internet
Author: User

If the URL is/home/index?id=3 direct request is OK.

But if the route is set to: {Controller}/{action}/{id}

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:


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.