MVC 5 + EF 6 Getting Started complete tutorial

Source: Internet
Author: User

Lesson No. 0 Starts from 0

The ASP. NET MVC development model adds a lot of "conventions" compared to the traditional WebForm development model.

It's confusing to talk about these "conventions" directly, and it's easy to forget things too much.

and Microsoft's official tutorial is different, the author try not to use scaffolding, starting from the blank frame, step by step add the function, each time adding something just enough, so that we can really use up, understand each process.

article outline
    • Overview
    • Core Concept Introduction
    • Start with a blank, create a basic framework detailed steps
Overview
    1. Examples of articles and articles in this series are based on official Microsoft documentation
    2. Using the tool: VS2013 + MS SQL 2012
    3. Starting with the MVC + EF mix, the following will also provide MVC + ADO. NET implementation Scenarios
Core Concept Introduction

Shorthand for Mvc,model–view–controller

Model Package business logic-related data and data processing methods

View provides an interactive interface to the user

Controller is responsible for controlling model and view

Look at this picture below. Now as long as you understand this concept can be, the following began to build an empty framework, from doing secondary school.

start with a blank, create a basic framework detailed steps
    1. New Project

Note: The template should be empty, and if you choose MVC directly, it will generate extra code.

Note: The box corresponds exactly to M, V, C

So far, a basic MVC solution has been built, essentially empty.

Let's briefly introduce the RouteConfig.cs file.

Open Global.asax and notice that the routing rules are registered when the program starts, as in the box below.

Let's look at the specific routing rules below. Open RouteConfig.cs File

Notice that there is a static method, which is the control of the map route, which defines the routing rules.

Where:URL: "{controller}/{action}/{id}" defines the format of the URL.

follow the actual URL address to explain.

    1. Add an example

Regardless of the model, we create the controller and the view first

    1. Add Controller

Right-click the Controllers folder and add it as shown.

Controllers must end with a controller (this is a convention for ASP.)

The following article will talk about user login examples, so here first build a accountcontroller.

You'll find more classes and folders at the box when you add them.

We opened the new AccountController.cs and looked at it, and it automatically generated a method

public actionresult Index ()

{

return View ();

}

We call this index an action with a return type of ActionResult.

As you can see, this action returns a view, and we now create this view

    1. Add view

There are two ways to add a view, one is to add it directly under the Views folder (right-click views à Account folder)

The other is to add it through the action in the controller. This time we used the latter method.

Open AccountController, right-click the index method, and add it as shown.

This adds a view that corresponds to a specific controller and action (this refers to AccountController and index). àindex.cshtml)

This view is the final display of the front page, we add a line of text inside the body.

Right-click on the index.cshtml to see the familiar HTML interface in the browser.

Note the address in the browser Xx/account/index

This address corresponds to the routing rule (URL: "{controller}/{action}/{id}") at the beginning and should be easily understood.

A typical process of execution.

    1. URL-to-route comparison
    2. If successful, execute the appropriate controller and action
    3. Executes the corresponding view and returns the result

Remember the process. The subsequent process will be extended in this simple process.

Summary

MVC has changed a lot more thoroughly than the previous WebForm development approach.

This article is mainly to let you build the basic concept of ASP.

The next article focuses on the UI design of the view and introduces some of the key HtmlHelper, which are easy to see from the front end.

All subsequent articles will be extended with this example, there are questions to welcome comments:)

MVC 5 + EF 6 Getting Started complete tutorial

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.