How 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}

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

Related Article

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: info-contact@alibabacloud.com 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.