asp.net-mvc ASP.NET MVC 向 Html.TextBoxFor 添加属性“数据消息”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19596232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET MVC Adding Attribute "data-message" to Html.TextBoxFor
提问by Ian Vink
Using MVC 4 I create a text box for a model property with the "data-message" attribute:
使用 MVC 4,我为具有“data-message”属性的模型属性创建了一个文本框:
@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.
匿名类型成员声明符无效。匿名类型成员必须使用成员赋值、简单名称或成员访问进行声明。
回答by Darin Dimitrov
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.
TextBoxFor 助手将知道要做什么并-在生成标记时将其替换。

![asp.net-mvc “[ValidateAntiForgeryToken]”的真正含义是什么?](/res/img/loading.gif)