从 ResourceFile / RIA 服务获取 ErrorMessage

发布于 2024-09-17 05:39:11 字数 446 浏览 3 评论 0原文

我的目标只是显示必需注释的特定于语言的错误消息:

[Required(ErrorMessageResourceName = "LastNameRequired", ErrorMessageResourceType = typeof(ValidationMessage))]

LastNameRequired 是资源文件中字符串的键,ValidationMessage 是资源文件生成的类型。资源文件位于同一项目和命名空间中。

我将资源文件的访问修饰符更改为public。构建操作位于嵌入式资源上。

实际的行为是,它不显示错误消息,甚至不显示该属性的错误。如果我从属性中删除 ErrorMessage*-Attribute,则一切正常。

[Required]

My goal is simply to show a language-specific errormessage for a Required-Annotation:

[Required(ErrorMessageResourceName = "LastNameRequired", ErrorMessageResourceType = typeof(ValidationMessage))]

LastNameRequired is the key of the string in the resourcefile, ValidationMessage is the type generated by the resource file. The resourcefile is in the same project and namespace.

I changed the Access Modifier of the resourcefile to public. Build Action is on Embedded Resource.

The actual behaviour is, that it doesn't show an errormessage, it even doesn't show an error for that attribute. If I remove the ErrorMessage*-Attribute from the Attribute, all works fine.

[Required]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

给妤﹃绝世温柔 2024-09-24 05:39:11

当您使用生成的资源类时,请检查它是否具有公共属性。默认情况下,资源仅具有内部属性,因此您必须在“解决方案资源管理器”中选择资源文件 (.resx),并在“属性”窗口中将自定义工具字段值“ResXFileCodeGenerator”替换为“PublicResXFileCodeGenerator”,然后重建解决方案...

When you use a generated resource class, check if it has public properties. Resources has only internal properties as default, so you must select the Resource file (.resx) in Solution Explorer and in window Properties replace Custom Tool field value "ResXFileCodeGenerator" with "PublicResXFileCodeGenerator" then rebuild solution...

戴着白色围巾的女孩 2024-09-24 05:39:11

我找到了解决方案。出现问题是因为我没有使用默认命名空间。我必须在项目文件中为链接的资源添加一个 - 元素。

I found the solution. The problem occured, because I didn't used the default-namespaces. I had to add a -element in the project file for the linked resources.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文