2013-10-25 10 views
27

に属性「データ・メッセージ」を追加:ASP.NET MVC私は、「データ・メッセージ」属性を持つモデルのプロパティのテキストボックスを作成MVC 4を使用してHtml.TextBoxFor

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

しかし、私が手次のエラー:

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

+0

ここに詳しい情報がありますhttp://stackoverflow.com/questions/2520487/how-to-use-html-5-data-attributes-in-asp-net-mvc –

答えて

72

使用_

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

TextBoxForヘルパーが何をすべきか知っているし、それをのwiを交換しますth -でマークアップを生成します。

+0

ありがとう@ダーリンと恥ずべきMVCはこの小さな事を処理しないように! – Amir978

+0

ありがとう!これは私に頭痛の多くを保存! –

+0

これは明らかではありません...ありがとう – shad0wec

関連する問題