我正在为我的网站制作一个注册表,目前我就是这样的 并且代码是:
@Html.Label("Firstname")
@Html.TextBoxFor(model => model.Firstname, new {@required = "require", @style = "width:75%;", @class = "form-control" })
@Html.ValidationMessageFor(model => model.Firstname, null, new { @style = "color:red;" })
<br />
@Html.Label("Surname")
@Html.TextBoxFor(model => model.Lastname, new { @required = "require", @style = "width:75%;", @class = "form-control" })
@Html.ValidationMessageFor(model => model.Lastname, null, new { @style = "color:red;" })
<br /> . . .
我想要做的是添加标题例如&#34;名字&#34;在文本框内,当输入数据时,它会消失,看起来像这样
我尝试过添加:
@name ="FirstName"
@label ="FirstName"
@title ="FirstName"
但所有这些都没有做任何事情。
答案 0 :(得分:3)
您在谈论placeholder。它是一个HTML属性,只需将其添加到自定义htmlAttributes
参数中即可:
@Html.TextBoxFor(model => model.Firstname, new {@required = "require", @style = "width:75%;", @class = "form-control", placeholder = "First Name" })
答案 1 :(得分:1)
您似乎在寻找Html5 placeholder attribute
@Html.TextBoxFor(model => model.Firstname, new {@required = "require", @style = "width:75%;", @class = "form-control", placeholder = "First Name" })
答案 2 :(得分:0)
这会为您的TextBox
@Html.TextBoxFor(model => model.Firstname, new {@required = "require",
@style = "width:75%;",
@class = "form-control",
@value = "FirstName"})
或者,如果您希望它在进入文本框时消失,
@Html.TextBoxFor(model => model.Firstname, new {@required = "require",
@style = "width:75%;",
@class = "form-control",
placeholder = "FirstName"})