Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Adding Attribute "data-message" to Html.TextBoxFor

Using MVC 4 I create a text box for a model property with the "data-message" attribute:

@Html.TextBoxFor(o => o.TradeOrder.Symbol, new {data-message="Required"}) 

However, I get the following error:

Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.

like image 564
Ian Vink Avatar asked Oct 25 '13 17:10

Ian Vink


1 Answers

Use _:

@Html.TextBoxFor(o => o.TradeOrder.Symbol, new {data_message="Required"}) 

The TextBoxFor helper will know what to do and replace it with - when generating the markup.

like image 194
Darin Dimitrov Avatar answered Sep 22 '22 18:09

Darin Dimitrov