ASP. net mvc Routing, Areas, URLs

Source: Internet
Author: User

When the webForm page is running, the url is generally like this: localhost: *****/index. aspx, this process is when you run the page, the microserver that comes with vs development tool will open this file on your hard disk and display it on the browser, therefore, the second half of the url is the name of the page (index. aspx), but in mvc, it is like this: localhost: ***/index, because mvc has a complete set of browser mechanism to control browser requests. Look at Global. routing definition in the asax file: copy the code public static void RegisterRoutes (RouteCollection routes) {routes. ignoreRoute ("{resource }. axd/{* pathInfo} "); routes. mapRoute ("Default", // route name "{controller}/{action}/{id}", // URL with parameters new {controller = "Home ", action = "Index", id = UrlParameter. optional} // default value of the parameter);} copy the code to comment out the default route and re-define a route: According to the prompt of vs, you can only see that one parameter is the route name, A routing mode is defined as routes. mapRoute ("MyRoute", "{cont Roller}/{action} "); you can create a Controller with a route. Create a HomeController: copy the code public class HomeController: Controller {public ActionResult Index () {return View () ;}} copy the code to create a corresponding View: copy the code @ {Layout = null ;}<! DOCTYPE html>

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.