gpt4 book ai didi

c# - 在 C# 中为模型上的属性设置默认资源类型

转载 作者:太空宇宙 更新时间:2023-11-03 14:15:50 25 4
gpt4 key购买 nike

我正在寻找一种更简单/更简洁的方法来使用我的 MVC 3 模型的资源。

我现在就是这样做的(每个属性都需要被告知它使用的是哪种资源类型):

    public class ContactMessageModel:BaseModel
{
[Display(Name="ReplyToEmail_DisplayName", ResourceType = typeof(Res.Views_Contact))]
public string ReplyToEmail {get; set; }

[Display(Name = "ContactReason_DisplayName", ResourceType = typeof(Res.Views_Contact))]
public string ContactReason { get; set; }

这可以做到吗?

这就是我想要的方式(我只想为模型定义一次资源类型):

[Display(ResourceType = typeof(Res.Views_Contact))]
public class ContactMessageModel:BaseModel
{
[Display(Name="ReplyToEmail_DisplayName")]
public string ReplyToEmail {get; set; }

[Display(Name = "ContactReason_DisplayName")]
public string ContactReason { get; set; }

最佳答案

似乎不可能,因为属性实例需要访问它所在的属性,而 .NET 不支持。

关于c# - 在 C# 中为模型上的属性设置默认资源类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6610493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com