DisplayAttribute 在 Dotnet Core 伙伴中不起作用 class

DisplayAttribute not work in Dotnet Core buddy class

我一直在尝试将 DisplayAttribute 附加到我伙伴 class 在 Dotnet Core 中的一个字段,但它没有出现在我的视图中。例如,在视图中显示 "Title" 而不是 "عنوان".

这两个 class 通过 ModelMetadataType 链接。

哪里错了?

原创博客class:

namespace KuteCore.Models
{
    public partial class Blogs
    {
        public int BlogId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
    }
}

博客元数据class:

namespace KuteCore.Models.MetaData
{
    public class BlogsMetadata
    {
        [Display(Name ="عنوان")]
        [Required(ErrorMessage ="خطااا")]
        public string Title { get; set; }
        [Display(Name = "توضیحات")]
        public string Description { get; set; }
    }
}

namespace KuteCore.Models.MetaData
{
    [ModelMetadataType(typeof(CategoryMetadata))]
    public partial class Category
    {
    }
}

这是我的观点

@model KuteCore.Models.Blogs
    <div class="form-group">
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
                </div>
                @Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })


            </div>

            <div class="form-group">
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
                </div>
                @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })


            </div>

我找到问题所在了。我将元数据 类 放在 One 命名空间中,问题已解决

namespace KuteCore.Models
{
    [ModelMetadataType(typeof(BlogsMetadata))]
    public partial class Blogs { }
    public class BlogsMetadata
    {
        [Display(Name ="عنوان")]
        [Required(ErrorMessage ="خطااا")]
        public string Title { get; set; }
        [Display(Name = "توضیحات")]
        public string Description { get; set; }
    }
}