Document

MVC HTML辅助类常用方法记录

(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>

 

帮你解释一下, 你需要了解清楚了,你的记录才有意义。
(1)@Html.DisplayNameFor(model => model.Title)是显示列名,

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

这两个你的说法是有误区的。

(1) :中model和model.Title 其实是一个lambda表达式,而且Model是会被传递给(1)的,然后model被赋值成了Model新的模型绑定内容。
(2):中的modelItem,其实无所谓,真正的是说,通过闭包调用了,foreach中的item元素而已。

你这样简单的记录,其实是错误的!

 

posted @ 2016-01-27 11:40  从未被超越  阅读(228)  评论(0编辑  收藏  举报