无法从部分 class 访问数据注释
Unable to access data annotation from partial class
使用 ASP.NET MVC 模式,我有一个 Entity Framework 存储在 Models->Northwind
中,其中包括 Region.cs
class。我还有一个 Partial
文件夹,其中包含 RegionalPartial.cs
,其中包括 region.cs
的数据注释
这是目录结构
Region.cs
看起来像:
namespace Map.Models.Northwind
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class Region
{
public int RegionID { get; set; }
public string RegionDescription { get; set; }
}
}
而 RegionPartial.cs
就像
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Map.Models.Northwind.Partials
{
using System.ComponentModel.DataAnnotations;
[MetadataType(typeof(RegionMetaData))]
public partial class Region {}
public class RegionMetaData
{
[Required]
[Display(Name = "REGION DESCRIPTION")]
public object RegionDescription { get; set; }
}
}
但是 Region.cs
没有使用存储在 RegionPartial.cs
中的数据注释!为什么会发生这种情况,我该如何解决?
将 RegionPartial.cs
中的命名空间从
更改为
Map.Models.Northwind.Partials
至
Map.Models.Northwind
使用 ASP.NET MVC 模式,我有一个 Entity Framework 存储在 Models->Northwind
中,其中包括 Region.cs
class。我还有一个 Partial
文件夹,其中包含 RegionalPartial.cs
,其中包括 region.cs
这是目录结构
Region.cs
看起来像:
namespace Map.Models.Northwind
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class Region
{
public int RegionID { get; set; }
public string RegionDescription { get; set; }
}
}
而 RegionPartial.cs
就像
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Map.Models.Northwind.Partials
{
using System.ComponentModel.DataAnnotations;
[MetadataType(typeof(RegionMetaData))]
public partial class Region {}
public class RegionMetaData
{
[Required]
[Display(Name = "REGION DESCRIPTION")]
public object RegionDescription { get; set; }
}
}
但是 Region.cs
没有使用存储在 RegionPartial.cs
中的数据注释!为什么会发生这种情况,我该如何解决?
将 RegionPartial.cs
中的命名空间从
Map.Models.Northwind.Partials
至
Map.Models.Northwind