Reputation: 709
I am making a registration form for my website, and currently i have it like this
and the code for that is :
@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 /> . . .
What i am trying to do is to add the title for example "First Name" inside the textbox, when data is entered it would disappear, To look like this
I have tried adding:
@name ="FirstName"
@label ="FirstName"
@title ="FirstName"
but all of those did nothing.
Upvotes: 0
Views: 3025
Reputation: 6839
You are talking about placeholder. It's a HTML attribute, just add it to the custom htmlAttributes
parameters, for exemple:
@Html.TextBoxFor(model => model.Firstname, new {@required = "require", @style = "width:75%;", @class = "form-control", placeholder = "First Name" })
Upvotes: 3
Reputation: 34992
It seems you are looking for the Html5 placeholder attribute
@Html.TextBoxFor(model => model.Firstname, new {@required = "require", @style = "width:75%;", @class = "form-control", placeholder = "First Name" })
Upvotes: 1
Reputation: 934
This will add default value to your TextBox
@Html.TextBoxFor(model => model.Firstname, new {@required = "require",
@style = "width:75%;",
@class = "form-control",
@value = "FirstName"})
Or if you want it to dissapear on entering the textbox
@Html.TextBoxFor(model => model.Firstname, new {@required = "require",
@style = "width:75%;",
@class = "form-control",
placeholder = "FirstName"})
Upvotes: 0