html帮助器使用razor语法重载

时间:2013-04-19 11:32:11

标签: asp.net-mvc razor html-helper

  @Html.TextBox("displayName", ViewData["cusDispName"], new { @class = "k-textbox", id = "CusMainDispName", disabled = "disabled" })

我需要帮助用razor语法理解上面的代码行。

特别是代码的这一部分。

new { @class = "k-textbox", id = "CusMainDispName", disabled = "disabled" })

这与CSS有关,但我无法清楚。

1 个答案:

答案 0 :(得分:0)

如果您提供@Html.TextBox("displayName", ViewData["cusDispName"], new { @class = "k-textbox", id = "CusMainDispName", disabled = "disabled" }),则在您的网页上创建texbox元素时,它将具有以下HTML属性:

class = "k-textbox"
id = "CusMainDispName"
disabled = "disabled"
value = (Whatever you have passed in ViewData["cusDispName"])
name = "displayName"

如果您只提供@Html.TextBox("displayName", ViewData["cusDispName"])

id = "displayName"
name = "displayName"
value = (Whatever you have passed in ViewData["cusDispName"])

第三个参数是包含键 - 值对的Dictionary。键将是您要设置的html属性,值将是属性的值。