ASP. NET MVC Learning Memo

Source: Internet
Author: User

Reference Book Pro ASP mvc5, HTTP://ASP.NET/MVC

ASP. NET MVC is an alternative to traditional ASP. Web Forms, there are many people who are criticized. MVC is not unique to ASP. Microsoft has emulated rails.

M model Models

V View View

C Control Controller

Each method in the controller is called an action, and each action corresponds to a view,

View is not a full page, but a partial page. Navigation, the bottom and other common parts, placed in the layout file.

M is used to build the model. The work of rendering the data is done in view, the view is a cshtml file, C # and HTML mixed files, through razor syntax, @{} to embed C # code in HTML.

The creation of a data table, read, modify, delete operations, including the establishment of the database are automatically completed.

Now there are a few questions,

1. How to work with data in an associated table

2. How to control the data table generated by the model, the definition of the model can refer to http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.aspx


There is a @model in view that determines the current view, the operation of the data model, can be a list, a class. A recordset corresponds to a class for a list, one record.

The model is passed to view through the method view () in control.

3. What are the @html methods? such as @html.displayfor, @html. ActionLink, and so on. For details, refer to Htmlhelper,http://msdn.microsoft.com/en-us/library/system.web.mvc.htmlhelper (v=vs.108). aspx


All kinds of wrong state, have corresponding class to deal with, before all is their own write error processing. Now this method is obviously more conducive to testing and modification.

such as Httpnotfound (), Httpstatuscode.badrequest ()


To prevent the forgery of client input can be @html.antiforgerytoken (), generates a hidden form field (Anti-forgery token) that's validated when the for M is submitted.

The Bind method of 4.model

5.LINQ query syntax, http://msdn.microsoft.com/en-us/library/bb397926.aspx

6.lambda expression http://msdn.microsoft.com/en-us/library/bb397687.aspx

7. For more information on the query, refer to this link, and now very few directly build SQL statements. Http://msdn.microsoft.com/en-us/library/bb738633.aspx

8. The default generated pages, many operations are in English. There is no place to set up and save cross-cultural translations, support multiple languages.?

9. How does automated testing work?


Here are the questions that arise when you look at the article earlier. Find some answers.


The definition of the model can be referenced by the System.ComponentModel.DataAnnotations namespace provides attribute classes that is used to  Define metadata for ASP. NET MVC and ASP. This definition affects both the database definition and client authentication. If you can set key, regular expression validation, maximum length, minimum length, range of values, specify data type, specify data display format DisplayFormat, etc.

After modifying the model definition, you can delete the corresponding data table for rebuilding. Or use Code First migrations


@html is a helper that is used to produce some HTML content. Is it necessary to set another layer on the HTML?

The benefit of LINQ is that it supports a wider range of databases, such as Sql,xml. LINQ functions like SQL, and can be used to look at how LINQ is implemented. I was familiar with it a few times later.

Limbda can be understood as a function body without function declaration, the left is an input parameter, the right is a logical result, and the return is the result of the logical operation on the right.




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.