I something similar to the following
class EntityNameId
{
public string Name { get; set; }
public string Id { get; set; }
}
class OrganizationNameId : EntityNameId
{
}
class PersonViewModel
{
public PersonViewModel()
{
Organization = new OrganizationNameId();
}
OrganizationNameId Organization { get; }
}
How can I set the Required
attribute in PersonViewModel
for OrganizationNameId.Id
so that client-side validation will work? I don't want to put it in OrganizationNameId
or EntityNameId
because its not always required, but it is required for PersonViewModel
. I am using MVC 3.
Edit: I do not want to add a custom property as described below by Bas. I have a custom partial view for EntityNameId
that allows for it to be reusable.