MVC HTML辅助类常用方法记录

时间:2021-03-04 19:19:06

(1)@Html.DisplayNameFor(model => model.Title)是显示列名,

(2)@Html.DisplayFor(modelItem => item.Title)是显示列的内容

(3)@Html.ActionLink("Create New", "Create")是超链接,跳转到model中的create页面,引用的是controller中create方法;

(4)@Html.ActionLink("Edit", "Edit", new { id=item.ID })编辑页面;

(5)@using (Html.BeginForm()) {   @Html.ValidationSummary(true)}用于客户端验证,其Html.BeginForm()表示在本页显示

(6)<div class="editor-label">
            @Html.LabelFor(model => model.Time)标签
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Time)编辑框
            @Html.ValidationMessageFor(model => model.Time)验证合法性错误显示
        </div>