31
votes

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.

1
here is a link with more information stackoverflow.com/questions/2520487/…Matt Bodily

1 Answers

80
votes

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.