在 MVC2 之后,开始支持一系列强类型的方式来生成 HTML. 这些方法的名字形式为 Html.HelperNameFor() , 例如,Html.TextBoxFor(), Html.CheckBoxFor() 等等。

例如,使用下面的形式:

MVC2 强类型的 HTML Helper

需要注意的是,这是一个 Lambda 表达式,所以,我们并不需要写出 ProductName 来。在 VS 中,通过强类型的 Model,当使用 Lambda 表达式的时候,Visual Studio 可以给出提示。

MVC2 强类型的 HTML Helper

生成的 HTML 如下所示:

MVC2 强类型的 HTML Helper

在 ASP.NET MVC2 中支持的方式如下:

HTML 元素的助手

  • Html.TextBoxFor()
  • Html.TextAreaFor()
  • Html.DropDownListFor()
  • Html.CheckboxFor()
  • Html.RadioButtonFor()
  • Html.ListBoxFor()
  • Html.PasswordFor()
  • Html.HiddenFor()
  • Html.LabelFor()

还有其它的助手

  • Html.EditorFor()
  • Html.DisplayFor()
  • Html.DisplayTextFor()
  • Html.ValidationMessageFor()

相关文章:

  • 2021-08-16
  • 2021-06-26
  • 2021-09-30
  • 2022-12-23
  • 2021-07-02
  • 2022-01-15
  • 2021-12-01
猜你喜欢
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
相关资源
相似解决方案