Does MVC4
by default support placeholders
for generated input fields? I didn\'t found anything so I am trying to implement my own but unfortunately
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control",@placeholder = "Name" })
I did so
Field in model:
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
Razor:
<li>
@Html.TextBoxFor(m => m.UserName, new { placeholder = Html.DisplayNameFor(n => n.UserName)})
</li>
Try this:
@Html.TextbBoxFor(x=>x.Email,new { @placeholder=@viewBag.email}
If this possible or else what could be the way
Of course it does:
@Html.TextBoxFor(x => x.Email, new { @placeholder = "Email" })
This works:
@Html.TextBox("name", null, new { placeholder = "Text" })
There are such of ways to Bind a Placeholder to View:
1) With use of MVC Data Annotations:
Model:
[Required]
[Display(Prompt = "Enter Your First Name")]
public string FirstName { get; set; }
Razor Syntax:
@Html.TextBoxFor(m => m.FirstName, new { placeholder = @Html.DisplayNameFor(n => n.UserName)})
2) With use of MVC Data Annotations But with DisplayName:
Model:
[Required]
[DisplayName("Enter Your First Name")]
public string FirstName { get; set; }
Razor Syntax:
@Html.TextBoxFor(m => m.FirstName, new { placeholder = @Html.DisplayNameFor(n => n.UserName)})
3) Without use of MVC Data Annotation (recommended):
Razor Syntax:
@Html.TextBoxFor(m => m.FirstName, new { @placeholder = "Enter Your First Name")