Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC调用属性中的资源文件_C#_Model View Controller - Fatal编程技术网

C# MVC调用属性中的资源文件

C# MVC调用属性中的资源文件,c#,model-view-controller,C#,Model View Controller,我想通过在“Oninvalid”属性中显示资源文件中的错误消息,使显示的错误消息本地化,以下是我的代码: @Html.TextAreaFor(x => x.Message, new { @class = "form-control notifi-form-field", @name = "Message", @id = "MessageText",@oninvalid= "this.setCustomValidity('Resources.LayoutResources.RequiredF

我想通过在“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
按原样显示。
这只是从服务器端代码发送到客户端代码的字符串文字:

"this.setCustomValidity('Resources.LayoutResources.RequiredField')"
对资源的引用需要由服务器端代码解释,因此它需要知道它不仅仅是一个字符串文本。例如:

$"this.setCustomValidity('{Resources.LayoutResources.RequiredField}')"
或使用较旧的语法:

"this.setCustomValidity('" + Resources.LayoutResources.RequiredField + "')"
请注意,在服务器端代码发出字符串值后,仍然存在单引号,以使生成的客户端代码有效