model.Age, htmlAttributes: new { @class = "control-label col-md-2" }) @Html.EditorFor...model.Money, htmlAttributes: new { @class = "control-label col-md-2" }) @Html.EditorFor...model.Pass, htmlAttributes: new { @class = "control-label col-md-2" }) @Html.EditorFor...model.RPass, htmlAttributes: new { @class = "control-label col-md-2" }) @Html.EditorFor...model.Email, htmlAttributes: new { @class = "control-label col-md-2" }) @Html.EditorFor
Html.LabelFor(model => model.Author) @Html.EditorFor...Html.LabelFor(model => model.Price) @Html.EditorFor...Html.LabelFor(model => model.Remark) @Html.EditorFor...Html.LabelFor(model => model.Author) @Html.EditorFor...Html.LabelFor(model => model.Price) @Html.EditorFor
new { @class = "control-label col-md-2" }) @Html.EditorFor...new { @class = "control-label col-md-2" }) @Html.EditorFor...new { @class = "control-label col-md-2" }) @Html.EditorFor...new { @class = "control-label col-md-2" }) @Html.EditorFor...new { @class = "control-label col-md-2" }) @Html.EditorFor
class = "control-label col-md-2" }) @Html.EditorFor...class = "control-label col-md-2" }) @Html.EditorFor...class = "control-label col-md-2" }) @Html.EditorFor...class = "control-label col-md-2" }) @Html.EditorFor...class = "control-label col-md-2" }) @Html.EditorFor
ModelMetadata表示的Model元数据的一个主要的作用在于为定义在HtmlHelper和HtmlHelper中的模板方法(这些模板方法包括Display/DisplayFor、Editor/EditorFor...1: @model Model 2: @Html.DisplayFor(m=>m.Foo) 3: @Html.EditorFor(m=>m.Foo) 分别以两种模式呈现出来的Foo属性对应的...1: @model Model 2: @Html.EditorFor(m=>m.Foo) 如下所示的代码片断表示Model的Foo属性呈现在UI界面中的HTML(“dummy text …”是是Foo...(m=>m.Foo) 5: @Html.EditorFor(m =>m.Bar) 上述四个元素在最终呈现的UI界面中对应着如下的HTML,我们可以看到最终显示的都是具有两位小数的数字。...1: @model Model 2: @Html.DisplayFor(m=>m.Foo) 3: @Html.EditorFor(m=>m.Foo) Model对象的Foo属性最终呈现出来的
ValueProvider基于索引的匹配策略也可以通过HtmlHelper的模板方法EditorFor来体现。...如下面的代码片断所示,在一个Model类型为Contact数组的强类型View中,我们调用HtmlHelper的扩展方法EditorFor将数组的前两个元素的相关信息以编辑模式呈现出来。...1: @model Contact[] 2: @Html.EditorFor(m => m[0].Name) 3: @Html.EditorFor(m => m[0].PhoneNo)...4: @Html.EditorFor(m => m[0].EmailAddress) 5: 6: @Html.EditorFor(m => m[1].Name) 7: @Html.EditorFor...(m => m[1].PhoneNo) 8: @Html.EditorFor(m => m[1].EmailAddress) 下面的XML片断代表了上面这段代码在最终生成的HTML中对应的6个类型为
editor-label"> 图书名称 @Html.EditorFor...="editor-label"> 作者 @Html.EditorFor..."editor-label"> 出版社 @Html.EditorFor...="editor-label"> 价格 @Html.EditorFor...@Html.EditorFor(model => model.BookName):根据模型生成模型中BookName的编辑控件(生成一个Input元素) @Html.ValidationMessageFor
Html.LabelFor(m => m.Baz) @Html.TextBoxFor(m => m.Baz) //第二种形式 @model DemoModel @Html.LabelFor(m=>m.Foo) @Html.EditorFor...(m => m.Foo) @Html.LabelFor(m => m.Bar) @Html.EditorFor (m => m.Bar) @Html.LabelFor(m => m.Baz) @Html.EditorFor
} 15: } 如下所示的是上面的Index操作对应的View定义,这是一个以Model类型为Employee的强类型View,我们通过调用HtmlHelper的模板方法EditorFor.../td> 5: 6: 7: @Html.LabelFor(m => m.Gender)@Html.EditorFor...> 8: 9: 10: @Html.LabelFor(m => m.Education)@Html.EditorFor...11: 12: 13: @Html.LabelFor(m => m.Departments)@Html.EditorFor... 14: 15: 16: @Html.LabelFor(m => m.Skills)@Html.EditorFor
请注意,代码如何使用Html.EditorFor helper 输出为Movie中的每个属性的元素。此Helper旁边是对Html.ValidationMessageFor方法的调用。...Html.LabelFor(model => model.Title) @Html.EditorFor...Html.LabelFor(model => model.Genre) @Html.EditorFor...Html.LabelFor(model => model.Price) @Html.EditorFor...editor-label"> @Html.LabelFor(model => model.Rating) @Html.EditorFor
实际上当我们调用HtmlHelper的模板方法EditorFor/EditorForModel的时候就是按照这样的匹配方式对标单元素进行命名的。...假设在将Contact作为Model类型的强类型View中,我们通过调用HtmlHelper的扩展方法EditorFor将Model对象的所有信息以编辑的模式呈现出来。...1: @model Contact 2: @Html.EditorFor(m => m.Name) 3: @Html.EditorFor(m => m.PhoneNo) 4: @Html.EditorFor...(m => m.EmailAddress) 5: @Html.EditorFor(m => m.Address.Province) 6: @Html.EditorFor(m => m.Address.City...) 7: @Html.EditorFor(m => m.Address.District) 8: @Html.EditorFor(m => m.Address.Street) 下面的代码片断代表了作为
(model => model.Name): @Html.EditorFor...(model => model.Sort): @Html.EditorFor...(model => model.Name): @Html.EditorFor...(model => model.Sort): @Html.EditorFor...(model => model.Name): @Html.EditorFor
Html.LabelFor(model => model.Result) @Html.EditorFor...Html.LabelFor(model => model.Type) @Html.EditorFor...Html.LabelFor(model => model.Module) @Html.EditorFor...Html.LabelFor(model => model.Source) @Html.EditorFor...Html.LabelFor(model => model.Data) @Html.EditorFor
class="control-label"}) 15: 16: @Html.EditorFor...class="control-label"}) 22: 23: @Html.EditorFor...= "control-label" }) 29: 30: @Html.EditorFor...= "control-label" }) 36: 37: @Html.EditorFor
model.Id): @Html.EditorFor...Html.LabelFor(model => model.Name): @Html.EditorFor...=> model.Age): @Html.EditorFor...> model.Note): @Html.EditorFor
col-md-2" }) @Html.EditorFor...col-md-2" }) @Html.EditorFor...col-md-2" }) @Html.EditorFor...col-md-2" }) @Html.EditorFor
Html.LabelFor(model => model.Id): @Html.EditorFor...(model => model.Name): @Html.EditorFor...model => model.Photo): @Html.EditorFor...(model => model.Note): @Html.EditorFor...=> model.CreateTime): @Html.EditorFor
正是这里泛型类型的类型参数,所以围绕着HtmlHelper的扩展方法才变成灵活的泛型的代码生成接口;因为他们彼此通过强大的泛型类型推断,依次的推断下去,最终会到达扩展方法的内部,如: @Html.EditorFor...画红线的部分是View所使用的强类型HtmlHelper对象,类型参数是我们在View中通过@model的方式定义的;画绿色的部分也是强类型的EditorFor方法,同样该泛型方法已经被类型推断过了...,看泛型方法的定义: public static class EditorExtensions { public static MvcHtmlString EditorFor<TModel, TValue
@Html.EditorFor... @Html.EditorFor
model.Title): @Html.EditorFor...model.Name): @Html.EditorFor
领取专属 10元无门槛券
手把手带您无忧上云