The use of razor and HtmlHelper

Source: Internet
Author: User

The use of Razor and htmlhelper

The purpose of this document is to introduce the two new concepts in MVC 's View to the novice MVC peers, which will help us develop projects faster and better. One is the view engine, and the other is Htmlhlper. Both of these are not new, and the concept of knowledge is new, and we have improved on the ASPX and Html we've learned, and it's easier for us to program.

One, the difference between ASPX and Razor

In the ASP . NET MVC pattern, our view engine is selected in two types:ASPX(asp),Razor.

1.ASP.

If you choose ASPX, then the engine you choose is the ASP . Let's talk about these issues before you start the ASP .

What is ASP.

  • asp . NET is a major part of the Microsoft

  • ASP . NET is a server-side scripting technique that enables scripts (embedded in Web pages) to be executed by an Internet server.

  • It is a combination of ASP and . NET Technology . Provides component-based, event-driven, programmable network forms that greatly simplify programming.

  • ASP . NET is a program that runs in IIS

    IIS (Internet Information Services) is Microsoft's Internet server

    IIS is a free bundled component of the Windows servers operating system

    IIS is also part of the Windows XP Professional Edition

What is an asp . net file?

  • asp . net files are like HTML files, but can contain HTML,XML , and scripts

  • The script in the ASP . net file executes on the server

  • The file suffix of the ASP . net file is ". aspx"

    How does asp work?

    when the browser requests an HTML file, the server returns the file

    when the browser requests an ASP . net file,IIS passes the request to the ASP . NET engine on the server

    The ASP . NET engine reads the file row by line and executes the script in the file

    Finally, theASP . net file will return to the browser in plain HTML form

2,Razor
    • What is Razor?

Razor is a markup syntax that allows you to embed server-based code (Visual Basic and C #) into a Web page. As you can see,Razor is actually a code template that is mixed with server code and HTML code, similar to an . aspx file without a post code.

    • File type

Razor supports two file types, the . cshtml and . vbhtml, where the . cshtml Server code uses the C # syntax. The vbhtml server code uses the vb.net syntax.

  

    • work: Server-based code can create dynamic content when a Web page is written to the browser. When the Web page loads, the server executes the server-based code within the page before returning the page to the browser. because it is running on a server, this code can perform complex tasks, such as accessing a database.

3. Comparison

with:

    • < P style= "Color:rgb (0,0,0); Font-style:normal; Font-weight:normal; margin-top:0cm; Margin-bottom:0pt ">HTML The technology for inserting server code in the.

    • execution order same

    • based on ASP.

Specialty:

    • Razor It is designed for the creation of Web applications, especially in MVC3 , serving the MVC pattern .

    • It has the capability of traditional ASP . NET notation, but it is simpler , easier to use and easier to learn than the ASP .

Conclusion :

So, this time developing the MVC pattern Project, the individual recommends using Razor as the development view engine.

Razor related syntax, with reference to use.

Using the syntax document description

Reference website:http://www.w3cschool.cc/aspnet/razor-intro.html

Second,HtmlHelper class
  1. Function: Generates an Html tag with data binding.

  2. Why does it appear? Many times we will encounter the following scenarios when writing a page to edit data, we usually write the following code<input type= "text" value= ' <%=viewdata["title"]%> ' name = "title"/>。 So we think, for this kind of code, we can also use aHelperFrom the dynamic binding data? Of course it's possible,ASP . NET MVCProvides aHtmlHelperUsed to generate a data-boundHtmlLabel. Look, there's nothing special about this class. is to assist us in usingHtmlA tool class for programming. InMVCMode, inView, we can directly pass this tool class (HtmlHelper) to read the data entity value, givingHtmlThe label is assigned a value.

3. Do you have to use Htmlhlper in View ?

This is primarily an HTML tag that requires data binding. For example, the form and Models binding, so in the MVC form and link is recommended with HTmlhelper, Others can be used as needed in Html and HtmlHelper to choose from.


4. Form

    Html tags that are similar to those taken in the form of Html.textbox() .

Reference for use: http://www.cnblogs.com/jyan/archive/2012/07/23/2604474.html

Since Microsoft has done so much work on MVC, it is certainly in favor of MVC, which helps us develop projects faster and better, and we are going to try to use them.

Hope to be of help to everyone.



The use of razor and HtmlHelper

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.