我希望通过在'Oninvalid‘属性中显示资源文件中的错误消息来显示本地化的错误消息,下面是我的代码:
@Html.TextAreaFor(x => x.Message, new { @class = "form-control notifi-form-field", @name = "Message", @id = "MessageText",@oninvalid= "this.setCustomValidity('Resources.LayoutResources.RequiredField')"})Resources.LayoutResources.RequiredField按原样显示。

发布于 2018-11-25 13:38:16
这只是从服务器端代码发送到客户端代码的字符串文本:
"this.setCustomValidity('Resources.LayoutResources.RequiredField')"对资源的引用需要由服务器端代码来解释,因此它需要知道它不仅仅是字符串文本。例如:
$"this.setCustomValidity('{Resources.LayoutResources.RequiredField}')"或者使用旧语法:
"this.setCustomValidity('" + Resources.LayoutResources.RequiredField + "')"请注意,在服务器端代码发出字符串值后,单引号仍然存在,因此产生的客户端代码是有效的。
https://stackoverflow.com/questions/53468000
复制相似问题