部分类中的DataAnnotations问题 [英] Problem with DataAnnotations in partial class
问题描述
所以在我的mvc项目的Project.Repository中,
So in my mvc project's Project.Repository I have
[MetadataType(typeof(FalalaMetadata))]
public partial class Falala
{
public string Name { get; set; }
public string Age { get; set; }
internal sealed class FalalaMetadata
{
[Required(ErrorMessage="Falala requires name.")]
public string Name { get; set; }
[Required(ErrorMessage = "Falala requires age.")]
public string Age { get; set; }
}
}
我在我的Project.Web.AccountControllers中使用Falala作为模型,并使用一种获取违规的方法. 拥有
I use Falala as a model in my Project.Web.AccountControllers, and use a method to get violations. Validating worked when I had
public class Falala
{
[Required]
public string Name { get; set; }
[Required(ErrorMessage="error")]
public string Age { get; set; }
}
,但在使用上面的分部类后不会出现. 我真的需要使用局部类.我在这里做什么错了?
but not after using the partial class from above. I really need to use a partial class. What am I doing wrong here?
谢谢!
推荐答案
嵌套类中的Internal是否可能是原因?
Could Internal on the nested class be the reason...?
我遇到了一个类似的问题,这似乎归结为不公开嵌套元数据类中的各个字段-想知道是否使整个类的内部出现相同的问题吗?
I had a similiar problem and it seemed to all boiled down to not making the individual fields in the nested metadata class public - wonder if making the whole class internal causes the same problem?
这篇关于部分类中的DataAnnotations问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!