Is there a way to have a data annotation for what should be in placeholder
attr on a textbox in an MVC view?
Example:
In my ViewModel.cs, something like:
[Placeholder="First name"]
public string FirstName { get; set; }
In my view:
@this.Html.TextBoxFor(m => m.FirstName)
If that could render this:
<input type="text" placeholder="First name" ... />
Is this possible? Thanks!
ComponentModel. DataAnnotations namespace that you can use to apply to (decorate) classes or properties to enforce pre-defined validation rules.
DataAnnotations is used to configure your model classes, which will highlight the most commonly needed configurations. DataAnnotations are also understood by a number of . NET applications, such as ASP.NET MVC, which allows these applications to leverage the same annotations for client-side validations.
try
@this.Html.TextBoxFor(m => m.FirstName, new{placeholder="First name"})
Ah, not in the model.
You can define your own custome attribute http://blogs.msdn.com/b/aspnetue/archive/2010/02/24/attributes-and-asp-net-mvc.aspx. I think you will need a custom html helper to generate the html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With