System.Web.Mvc.Html 命名空间小计
1,Html.Action 使用指定参数调用指定子操作方法并以 HTML 字符串形式返回结果。
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 <div id="HtmlAction">
2
3 @Html.Action("ActionName");
4
5 @Html.Action("ActionName", "ControlName");
6
7 @{
8 object a = null;
9
10 }
11 @Html.Action("ActionName", a);
12
13 @{
14 RouteValueDictionary rotevalue = new RouteValueDictionary();
15 rotevalue.Add("Key", "Value");
16 }
17
18 @Html.Action("ActionName", rotevalue);
19
20 @Html.Action("ActionName", "ControlName", rotevalue);
21
22 @Html.Action("ActionName", "ControlName", "ObjectValue");
23
24 </div>
2,Html.RenderAction 通过Controller中的Action来调用用户控件 允许直接调用某一个Action,并把返回的结果直接显示在当前调用的View中
Html.RenderPartial 直接将用户空间嵌入到界面上
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 @{
2 Html.RenderAction("ActionName"); //优点 可以呈现不同的PartialView()
3 Html.RenderAction("ActionName", "ControlName");
4
5 object b = null;
6 Html.RenderAction("ActionName", b);
7 RouteValueDictionary rotevalue1 = new RouteValueDictionary();
8 rotevalue1.Add("Key","Value");
9 Html.RenderAction("ActionName", rotevalue);
10
11 Html.RenderAction("ActionName", "ControlName", rotevalue);
12
13 Html.RenderAction("ActionName", "ControlName", "ObjectValue");
14
15 Html.RenderPartial("~/Areas/Common/Views/Shared/UserControl.ascx"); //直接将用户控件嵌套到界面上
16 object model = null;
17 ViewDataDictionary viewdata = new ViewDataDictionary();
18 viewdata.Add("Key", "Value");
19 Html.RenderPartial("UserControl", model);
20 Html.RenderPartial("UserControl", model,viewdata);
21 }
3,Html.Display() 使用字符串来表示要呈现的对象值。
Html.DisplayFor() 使用模型对象表示要呈现的对象值。
Html.DisplayForModel() 隐式使用模型表示要呈现的对象值。
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 @model Azurebrite.Areas.Accounts.Models.Domain.LogOnModel
2 @{
3 //显示 Model.UserName
4 Html.Display("UserName");
5 Html.DisplayFor(m=>m.UserName);
6 Html.DisplayForModel(); //显示Model的全部字段
7 }
4,Html.DisplayText()
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 //返回指定表达式所表示对象中的每个属性所对应的 HTML 标记。
2 Html.DisplayText("UserName");
3 Html.DisplayTextFor(m => m.UserName);
5,Html.Editor()
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 //生成TextArea
2 Html.Editor("UserName");
3 Html.EditorFor(m=>m.UserName);
4 Html.EditorFor(m => m.UserName);
5 Html.EditorForModel(); //返回模型中的每个属性所对应的 HTML input 元素。
6,Html.BeginForm()
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 @using (Html.BeginForm("/myformrouteurl")) //Url
2 {
3 <!-- form here -->
4
5 }
6
7
8 @using (Html.BeginRouteForm("DefaultRote"))
9 {
10 <!-- form here -->
11
12 }
13
14 @using (Html.BeginRouteForm("DefaultRote", FormMethod.Post))
15 {
16 <!-- form here -->
17
18 }
7,Html Input
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 @{
2 Html.CheckBox("RememberMe");
3 Html.CheckBoxFor(m=>m.RememberMe);
4 Html.Hidden("UserName");
5 Html.HiddenFor(m=>m.UserName,new {@id="id",@name="name" });
6 Html.Password("Password");
7 Html.PasswordFor(m=>m.Password);
8 Html.RadioButton("Name","Value");
9 Html.RadioButtonFor(m=>m.RememberMe,true, new { @id="radio1",@value="1", @name = "RememberMe" });
10 Html.RadioButtonFor(m=>m.RememberMe,false, new { @id="radio2",@value="2", @name = "RememberMe" });
11 Html.TextBox("UserName",new {@id="id"});
12 Html.TextBoxFor(m=>m.UserName,new {@id="id"});
13
14 Html.Label("UserName",new {@id="id",@width="100px"});
15 Html.LabelFor(m=>m.UserName,new {@style="width:100px,height:30px"});
16 Html.LabelForModel();
17
18
19 }
8,Html.ActionLink()
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 @{
2 Html.ActionLink("LinkText","ActionName");
3 Html.ActionLink("LinkText","ActionName","ControlName");
4 Html.ActionLink("LinkText","ActionName","ObjectRoutvalues",new {@id="id",@style="width:100px,color:red"});
5
6 Html.RouteLink("LinkText","RouteName");
7
8 }
9,Html.MvcForm()
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 @{MvcForm form = Html.BeginForm("ProcessForm", "Home");
2
3
4 form.EndForm();
5 }
以上代码纯属构意构,并未测试,如有问题,请自行调试!