Providing data annotation for placeholder attr for text field in MVC

Is there a way to have data annotation for what should be in the placeholder attr in the text box in the MVC view?

Example:

In my ViewModel.cs something like:

 [Placeholder="First name"] public string FirstName { get; set; } 

In my opinion:

 @this.Html.TextBoxFor(m => m.FirstName) 

If this can do it:

 <input type="text" placeholder="First name" ... /> 

Is it possible? Thanks!

+8
c # html5 asp.net-mvc viewmodel
source share
2 answers

to try

 @this.Html.TextBoxFor(m => m.FirstName, new{placeholder="First name"}) 

Ah, not in the model.

You can define your own custom attribute http://blogs.msdn.com/b/aspnetue/archive/2010/02/24/attributes-and-asp-net-mvc.aspx . I think you will need a special html helper to create html.

+10
source share

I don’t think so, but you can write your own helper and attribute to do this. http://www.aspnetwiki.com/page:creating-custom-html-helpers

0
source share

All Articles