The ASP. net mvc Framework does not have its own control, and the page display completely returns to the HTML writingCode. In addition, the Asp.net MVC framework also has two built-in help classes: htmlhelper and urlhelper. In addition, some help classes are also added in the mvccontrib Extension Project. In this way, we can use not only the complete HTML to compile the pages to be displayed, but also the help classes, however, HTML code must be generated at the end of the operation.
Let's take a look at the HTML that htmlhelper can help us generate. Let's look at the results.
<Div>
1. Generate a hyperlink using htmlhelper:
<% = Html. actionlink ("I Am a hyperlink", "") %>
<Br/>
2. Generate a form using htmlhelper:
<% Html. beginform ("Index", "simple", formediahod. Post, new {id = "myform"}); %>
<% Html. endform (); %>
<Br/>
3. Use htmlhelper to generate a form based on routing rules:
<% Html. beginrouteform (New {controller = "simple", Action = "Demo"}); %>
<% Html. endform (); %>
<Br/>
4. Use htmlhelper to generate a check box:
<% = Html. checkbox ("checkbox", new {id = "mycheckbox"}) %> check box
<Br/>
5. Use htmlhelper to generate the pull-up list box:
<% Var droplist = new list <selectlistitem> ();
For (INT I = 0; I <5; I ++)
{
VaR dropitem = new selectlistitem ();
Dropitem. value = I. tostring ();
Dropitem. Text = I. tostring ();
Droplist. Add (dropitem );
}
%>
<% = Html. dropdownlist ("mylist", droplist, new {style = "width: 100px;"}) %>
<Br/>
6. Use htmlhelper to generate hidden domains:
<% = Html. Hidden ("hidden") %>
<Br/>
7. Use htmlhelper to generate a list box:
<% Var list = new list <selectlistitem> ();
For (VAR I = 0; I <5; I ++)
{
VaR item = new selectlistitem ();
Item. value = I. tostring ();
Item. Text = I. tostring ();
List. Add (item );
}
%>
<% = Html. ListBox ("ListBox", list, new {style = "width: 100px;"}) %>
<Br/>
8. Use htmlhelper to generate the password input box:
<% = Html. Password ("password", "longgel") %>
<Br/>
9. Use htmlhelper to generate a single listener:
<% = Html. radiobutton ("radio", "boy", true) %> male
<% = Html. radiobutton ("radio", "girl", false) %> female
<Br/>
10. Use htmlhelper to generate some views (User Controls ):
<% Html. renderpartial ("partialview"); %>
<Br/>
11. Use htmlhelper to generate hyperlinks Based on routing rules:
<% = Html. routelink ("I Am a hyperlink generated by a route", new {controller = "simple", Action = "Index"}) %>
<Br/>
12. Use htmlhelper to generate rich text boxes:
<% = Html. textarea ("mytxtarea", new {style = "width: 300px; Height: 100px;"}) %>
<Br/>
13. Use htmlhelper to generate a text box:
<% = Html. Textbox ("mytxtbox", "I am a text box") %>
</Div>
In fact, you may have noticed that when we are using methods in htmlhelper, why do we need to add equal signs and some do not need them? In fact, in the methods in htmlhelper, as long as mvchtmlstring is returned, the value must be output using equal signs. Let's take a look at the generated results.
<Div>
1. Generate a hyperlink using htmlhelper:
<A href = "/"> I am a hyperlink </a>
<Br/>
2. Generate a form using htmlhelper:
<Form action = "/" id = "myform" method = "Post"> </form>
<Br/>
3. Use htmlhelper to generate a form based on routing rules:
<Form action = "/simple/demo" method = "Post"> </form>
<Br/>
4. Use htmlhelper to generate a check box:
<Input id = "mycheckbox" name = "checkbox" type = "checkbox" value = "true"/> <input name = "checkbox" type = "hidden" value = "false "/> check box
<Br/>
5. Use htmlhelper to generate the pull-up list box:
<Select id = "mylist" name = "mylist" style = "width: 100px;"> <option value = "0"> 0 </option>
<Option value = "1"> 1 </option>
<Option value = "2"> 2 </option>
<Option value = "3"> 3 </option>
<Option value = "4"> 4 </option>
</SELECT>
<Br/>
6. Use htmlhelper to generate hidden domains:
<Input id = "hidden" name = "hidden" type = "hidden" value = ""/>
<Br/>
7. Use htmlhelper to generate a list box:
<Select id = "ListBox" multiple = "multiple" name = "ListBox" style = "width: 100px;"> <option value = "0"> 0 </option>
<Option value = "1"> 1 </option>
<Option value = "2"> 2 </option>
<Option value = "3"> 3 </option>
<Option value = "4"> 4 </option>
</SELECT>
<Br/>
8. Use htmlhelper to generate the password input box:
<Input id = "password" name = "password" type = "password" value = "longgel"/>
<Br/>
9. Use htmlhelper to generate a single listener:
<Input checked = "checked" id = "radio" name = "radio" type = "radio" value = "boy"/> male
<Input id = "radio" name = "radio" type = "radio" value = "girl"/> female
<Br/>
10. Use htmlhelper to generate some views (User Controls ):
<Span style = "background-color: Red"> Hi, I am a part of the view (User Control) </span>
<Br/>
11. Use htmlhelper to generate hyperlinks Based on routing rules:
<A href = "/"> I am a hyperlink generated by a route </a>
<Br/>
12. Use htmlhelper to generate rich text boxes:
<Textarea Cols = "20" id = "mytxtarea" name = "mytxtarea" rows = "2" style = "width: 300px; Height: 100px;">
</Textarea>
<Br/>
13. Use htmlhelper to generate a text box:
<Input id = "mytxtbox" name = "mytxtbox" type = "text" value = "I Am a text box"/>
</Div>
In addition, there are validationmessage () and validationsummary () methods in htmlhelper, which will be written together next time you learn the verification.