ASP.Net MVC @Html类
Model中的类
using System.Web;
using System.ComponentModel;
public class GuestBook
{
public int Id { get; set; }
[DisplayName("显示姓名")]
public string Name { get; set; }
[DisplayName("电子邮件地址")]
public string Email { get; set; }
public string Infor { get; set; }
}
Model类型就是@model引入的主要模型(类型)
1, @Html.DisplayNameFor(model => model.Name) 输出 “显示姓名” 如果没有 [DisplayName("显示姓名")],则显示 Name
2, @Html.DisplayFor(modelItem1 => item.Name) 输出 item.Name的值
3, @Html.ActionLink("注册", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" }) 输出超链接参数为:超链接的名称,链接的目的 Action,连接的Controller,路由参数ID,html的属性以及值,<a href="/Account/Register" id="registerLink">注册</a>
4, @Html.ValidationSummary() 用于返回表单在后台验证的结果,默认为true,若false则另外多生成<div><<ul><li style="display:none"></li></ul></div>集中显示错
5, @Html.LabelFor(model => model.Name) 输出<label for="Name">Name</label>
6, @Html.EditorFor(model => model.Name) 输出<input class="text-box single-line" id="Name" name="Name" type="text" value="" />
7,@Html.ValidationMessageFor(model => model.Infor)输出<span class="field-validation-valid" data-valmsg-for="Email" data-valmsg-replace="true"></span>8
8,@using (Html.BeginForm("ActionName","ControllerName",FormMethod.method)) {...}输出 <form action="/Controller/Action" method="post">....</form>FormMethod.method默认POST
9, @Html.AntiForgeryToken() http://www.cnblogs.com/PigJar/archive/2011/07/08/PostOnly.html
10,@Html.HiddenFor(model => model.Id) 输出隐藏域<input ....type="hide" Value=model.id/>