gpt4 book ai didi

c# - 继承 View 模型和更改 DisplayName 数据注释

转载 作者:太空狗 更新时间:2023-10-29 20:39:25 25 4
gpt4 key购买 nike

我有一个从基类 View 模型继承的 View 模型。我正在尝试更改继承类中的 DisplayName 元数据,但它不起作用。

这里是 View 模型:

namespace ViewModels
{
public class BaseViewModel
{
[DisplayName(Name = "Base Description")]
public virtual string Description { get; set; }
}

public class DerivedViewModel : BaseViewModel
{
[DisplayName(Name = "Derived Description")]
public override string Description { get; set; }
}
}

和 Controller :

    public ViewResult Create()
{
DerivedViewModel model = new DerivedViewModel();
model.Active = true;
return View(model);
}

呈现 View 时,预期的显示名称是“Derived Description”,但我得到的是“Base Description”。

使用:MVC 5.1、.NET Framework 4.5、Visual Studio 2013

谁能告诉我如何覆盖派生类中的显示数据注释?

最佳答案

现在已经修复了。引入了最新的 jQuery 和 jQuery unobtrusive,这解决了这个问题。

关于c# - 继承 View 模型和更改 DisplayName 数据注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22170597/

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