An Introduction to MVC Learning Notes (i) First MVC application (Basics)

Source: Internet
Author: User
Tags microsoft website


Downloaded and installed visual Studio Ultimate RC and MS SQL Server 2014. With the latest version, you can learn and learn about the newest technologies.






Go to the official Microsoft website and learn about MVC tutorials:
Http://www.asp.net/mvc


To listen to the recommended MVC video on Microsoft's website, although it is taught in English, watch the operation ...
http://pluralsight.com/training/player?author=scott-allen&name=mvc4-building-m1-intro&mode=live& Clip=0&course=mvc4-building


Buy an MVC book, "ASP. NET MVC 4 Web Programming":



Finally, create your own first MVC application, select the Visual C # language and. NET Framework4.5:

The project has been created and you can see that some files have been created for us in the solution, as well as some references

Where the folder controllers is the place where the controller is placed (it can be summed up to this folder as the previous. cs file, which can be understood, but that's not the case)

Folder models is where the data model resides

Folder views are places where pages are displayed (that is, files with the. aspx suffix)

We look back at the folder path, and we have learned the path in the ASP. NET is very different, in fact, the paths here are rewritten, specifically where to rewrite, we look at "Global.asax", Find "Global.asax.cs":

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Using System.Web.Routing;

Namespace Mvcdemo
{
Note: For instructions on enabling IIS6 or IIS7 Classic mode,
Please visit http://go.microsoft.com/?LinkId=9394801

public class MvcApplication:System.Web.HttpApplication
{
public static void RegisterRoutes (RouteCollection routes)
{
Routes. Ignoreroute ("{resource}.axd/{*pathinfo}");

Routes. MapRoute (
"Default",//route name
' {controller}/{action}/{id} ',//URL with parameter
New {controller = "Home", action = "Index", id = urlparameter.optional}//parameter default value
);

}

protected void Application_Start ()
{
Arearegistration.registerallareas ();

RegisterRoutes (routetable.routes);
}
}
}

The core code is:

public static void RegisterRoutes (RouteCollection routes)
{
Routes. Ignoreroute ("{resource}.axd/{*pathinfo}");

Routes. MapRoute (
"Default",//route name
' {controller}/{action}/{id} ',//URL with parameter
New {controller = "Home", action = "Index", id = urlparameter.optional}//parameter default value
);

}

This static method is used to rewrite the path, you can see the routes. MapRoute (
"Default",//route name
' {controller}/{action}/{id} ',//URL with parameter
, this is the format of the URL that will be rewritten in the future

Explain an Index method under the Home controller in our Url:http://localhost:2906/home/index, not the file path we normally see.

All right, just write it down here and keep trying.

An Introduction to MVC Learning Notes (i) First MVC application (Basics)

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.