In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the foundations of ASP.NET MVC". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the basics of ASP.NET MVC.
What is ASP.NET MVC?
(1) ASP.NET MVC is a framework for writing ASP.NET Web applications in MVC mode provided by Microsoft officially.
(2) MVC is a development method of Microsoft after ASP.NET WebForms, not an alternative!
(3) official website: http://www.asp.net/mvc
(4) Source website: http://aspnet.codeplex.com/wikipage?title=MVC
Characteristics of ASP.NET MVC
(1) Separation of tasks with low coupling
(2) High scalability
(3) powerful URL rewriting (routing) mechanism
(4) compatible with the existing technologies of ASP.NET
(5) Open source
Advantages of ASP.NET MVC
(1) make complex projects easier to maintain by dividing them into MOdel,View and Controller.
(2) without using ViewState and server form controls, it is more convenient to control the behavior of the application (it can be said that it has returned to the original state)
(3) applications control program requests through Controller, which can provide rich url rewriting.
(4) support test-driven development
(5) perform better in team mode
Why do we need ASP.NET MVC?
(1) Separation of concerns
(2) High scalability
(3) better testability
(4) better URL rewriting
(5) better performance
(6) more flexible HTML code control
ASP.NET MVC1
(1) after a long period of Preview and two RC versions, Microsoft officially released ASP.NET MVC1 in March 2009.
(2) at this time, Microsoft's first WebApplication framework in the MVC field brought a development concept that was almost different from that of WebForm.
(3) however, due to some reasons, key technical points such as Area are missing in this version, so there are many difficulties in developing complex MVC Web applications with this version.
ASP.NET MVC2
(1) ASP.NET MVC2 was officially released less than a year after the release of 1.0.
(2) VS2010 and Visual Web Developer 2010 official version were released on April 12, 2010, with built-in extensions to ASP.NET MVC2.
(3) ASP.NET MVC2 brings us many long-awaited functions, such as strongly typed HTML Helper, data validation, custom templates, Area, asynchronous Controller and so on.
(4). The new technology of NET 4 also brings some good new experiences to ASP.NET MVC2 application development, such as: dynamic type, with default worthwhile method parameters and so on.
Why do I need ASP.NET MVC3?
(1) ASPX views are full of
(2) Action filter cannot be global
(3) lack of corresponding ActionResult type for http response status of 404301302, etc.
(4) lack of direct support for Model data validation
(5) for dependency injection (DI), control inversion (IoC) support is not good enough.
(6) Grid is not supported
(7) ViewData is a bit troublesome to use (using dynamic type instead)
ASP.NET MVC3
(1) add Razor view engine and support multi-view engine
(2) Global Action filter
(3) New ViewBag attribute (dynamic type), originally ViewData
(4) New ActionResult type
(5) Model Validation (verification of Model)
(6) JSON binding support
(7) dependency Injection (injection dependency)
(8) HTML5,CSS3
(9) partial output cache
(10) Enhancement of HtmlHelper
(11) NuGet (inherited by the VS2010 environment)
Razor View engine
(1) use @ instead
1) the grammar is simple and clear
2) easy to learn
3) VS2010 smart prompt and syntax coloring
(2) globally set default layout and other projects
Global Action filter
(1) the way of writing before 3.0
The copy code is as follows:
[HandleError]
Public class HomeController: Controller
{
.
}
(2) how to write after 3.0:
The copy code is as follows:
Public static void RegisterGlobalFilters (GlobalFilterCollection filters)
{
Filters.Add (new HandleErrorAttribute ())
}
New ActionResult type
(1) HttpNotFoundResult
four hundred and four
(2) RedirectResult
302\ 301
(3) HttpStatusCodeResult
Custom Http status code
Model Validation
(1) self-verification
(2) client verification
-> client authentication is enabled by default
(3) remote verification
Overview of Razor View engine
(1) ASP.NET MVC 3 comes with a view engine.
1) ASPX
2) Razor
(2) ASP.NET MVC 3 supports multi-view engine mechanism
(3) you can customize the default view engine in the project you specify.
1) Free of the above engines in MVC3
2) Spark
3) Nhaml
4) Ndjango
5) self-defined view engine
(4) the Razor view engine implements code-focused methods.
(5) characteristics
1) brief introduction, full of performance and fluency
-> minimize the number of typed characters needed to write a view template to achieve fast and smooth programming.
-> you don't have to interrupt programming to clearly mark the beginning and end of the service module. The Razor parser can automatically infer from your code
2) easy to learn
You can learn quickly if you are familiar with existing programming languages and HMTML skills.
3) you can work in any text editor
4) VS2010 added intelligent prompts to it.
5) support unit testing
(6) comparison between introduction and fluency
1) ASPX engine
($)
2) Razor engine
@ foreach (var p in products) {
@ p.Name ($@ p.Price)
}
The great @
(1) the starting position of the server-side code snippet in Razor starts with the @ symbol.
1) ASPX engine
2) Razor engine
@ {
Int Xero12
String name= "Han Yinglong"
}
(2) render output
1) encoded by HTML (placed to be attacked)
1) ASPX engine
2) Razor engine
@ model.Message
2) not encoded by HTML
1) ASPX engine
2) Razor engine
@ Html.Raw (model.Message)
(3) mixing code and markup
1) ASPX engine
2) Razor engine
@ foreach (var item in items) {
@ item.Prop
}
(4) mixing code and plain text
1) ASPX engine
Plain Text
2) Razor engine
@ if (foo) {
Plain Text
}
@ if (foo) {
@: Plain Text
}
(5) tagging is an element specially handled by Razor. Razor treats the internal content of the block as a block of content and does not render tags that contain those contents.
(this means rendering only the internal content, not the tag itself). This makes it convenient to render multi-line blocks of content that are not wrapped by HTML elements
(6) mixing expression with text
1) ASPX engine
Hello.
2) Razor engine
Hello @ title.@name
(7) Email address
1) hyl934532778@live.cn
Razor can automatically recognize Email addresses without being executed as server-side code
(8) two consecutive @ @ symbols are rendered as one @ symbol.
I Hava A Dream,@@Kencery
(9) display rendered output
1) ISBN@ (isbnNumber)
2) when the code to render the output does not have spaces or tag bits before it, we need to use parentheses to continue the rendered output that you display
(10) Server-side comments
1) ASPX engine
2) Razor engine
@ *
I Have a Dream
* @
(11) render output dynamic method
1) for outputs such as dynamic method return values, we can use parentheses to close the code.
@ (MyClass.MyMethod ())
(12) create a Razor delegate
1) We reuse some view logic by creating a Razor delegate
The copy code is as follows:
@ {
Func b =
@ @ item
}
@ b ("Bold this")
(13) mixed code in content
The copy code is as follows:
@ foreach (var p in products) {
@ p.ProductName
@ if (p.unitsInStock==0) {
@: (Out of stock)
}
Else if (the first parameter of p.unitsInStock is the name of Section
-> the second attempt is to set whether it is an area that must be filled with content
-> the meaning of the above code is to live a non-essential content area named head
(2) the content page populates the section named head by @ section head {...}.
_ ViewStart file
(1) under the project project\ view folder, add a file named
Files for _ ViewStart.cshtml (or VB's _ ViewStart.vbhtml)
(2) this file is used to define the common view code that you want to execute at the beginning of each view rendering, for example, we can declare the default layout properties in this file.
The copy code is as follows:
@ {
Layout = "~ / Views/Shared/_Layout.cshtml"
}
(3) because this code is executed at the beginning of each view, we do not need to display the layout in any single view file (unless we want to override the default value above).
Conversion from ASPX View to Razor View
(1) the modification of a file by hand?
1) cheat your father.
(2) write your own code and convert it with regular expressions.
1) the skill of regular expression is not good enough.
(3) then use the RazorConverter created by the famous telerick team.
Https://github.com/telerik/razor-converter
At this point, I believe you have a deeper understanding of "what is the basis of ASP.NET MVC". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.