ASP.NET MVC Data Annotations Persisting Between Layers
I am learning MVC, and in trying to separate my business layer I cannot get Data Annotations to persist between them. For Instance I would like the Name of a Column to persist throughout my application, so I have created a partial class to buddy up with my Persistence model, and a View Model to go with my View. However the View does not display the Display Name from the Partial Class. I have simplified my code to just show one property.
Persistence Model
public partial class tblPart
{
public string Description1 { get; set; }
}
Buddy Model
[MetadataType(typeof(Metadata))]
public partial class tblPart
{
private class Metadata
{
[Display(Name = "Description")]
public string Description1 { get; set; }
}
}
View Model
public class CreateQuotesPartsViewModel
{
public string Description1 { get; set; }
}
View
@Html.DisplayFor(a => CreateQuotesPartsViewModel.Description1)
And my column name is "Description1" when I want it to be Description. I am aware I can place the Annotation on the View Model, and if I do put it there, it displays properly. How can I make the annotation stay when placed in my domain layer?
链接地址: http://www.djcxy.com/p/56594.html上一篇: ModelState用于ASP.Net MVC中模型的属性子集
下一篇: ASP.NET MVC数据注解持久层之间