Reputation: 2190
I have a data contract class with data members in my WCF project and I want to reference them in my MVC project so I can apply data annotation validation to them
I can use the class object in my MVC project already the only problem is the validation.
In my WCF project my class has a property called PeopleOnTourCount
:
namespace VBSClient.BookingServiceClient
{
[DataContract]
[MetadataType(typeof(BookingTypeMetaData))]
public partial class BookingType
{
public BookingType() { }
}
public class BookingTypeMetaData {
[Required]
[Display(Name="People Count")]
[DataMember]
public int PeopleOnTourCount { get; set; }
}
}
I can't access any of my original properties inside the constructor and the annotations aren't binding either.
Upvotes: 0
Views: 1080
Reputation: 2190
Instead of using partial class, inherit from the object instead.
You can then apply your data annotations in the MVC project.
[MetadataType(typeof(BookingTypeMetaData))]
public class Test : BookingType {
public Test() {
}
}
public class BookingTypeMetaData {
[Required]
[Display(Name = "People Count")]
public int PeopleOnTourCount { get; set; }
}
This is how I'm going to deal with it unless a better answer is given :)
Upvotes: 1
Reputation: 150253
You can't bind two Partial classes from two separate Assembly to one class.
Partial classes should be in one assembly.
Upvotes: 0