Hi ,
I am facing problem to use validation for child property .Here is my scenario
I have a POCO Class like this which is self generated:
namespace JQGridTest.Models
{
using System;
using System.Collections.Generic;
public partial class SR_WorkDescription
{
public SR_WorkDescription()
{
this.SR_ResourceWithWork = new HashSet<SR_ResourceWithWork>();
}
public int WId { get; set; }
public Nullable<int> ProjectId { get; set; }
public Nullable<long> StatusId { get; set; }
public string Description { get; set; }
public string StartDate { get; set; }
public string CompletionDate { get; set; }
public virtual SR_Project SR_Project { get; set; }
public virtual ICollection<SR_ResourceWithWork> SR_ResourceWithWork { get; set; }
public virtual SR_Status SR_Status { get; set; }
}
}
I also add manually a model in which rhe property of the above class is defined
namespace JQGridTest.Models
{
public class WorkModel
{
[Required]
public string SelectedStatus { get; set; }
public List<SR_Status> StatusList { get; set; }
[Required]
public string SelectedProject { get; set; }
public List<SR_Project> ProjectList { get; set; }
[Required]
public string SelectedResource { get; set; }
public List<SR_Resource> ResourceList { get; set; }
[Required]
public SR_WorkDescription WorkDescription { get; set; }
}
}
I also define a metadata type to apply validation
[MetadataType(typeof(SR_WorkDescriptionMetaData))]
public partial class SR_WorkDescription
{
private class SR_WorkDescriptionMetaData
{
[Required]
public object Description;
}
}
In my view I am doing like this
<td>@Html.TextAreaFor(x => x.WorkDescription.Description)
@Html.ValidationMessageFor(x => x.WorkDescription.Description, "Please Enter Description")
</td>
Through this i want to apply validation on "Description" field which lies in SR_WorkDescription
Please help me to sort out the problem
Thanks !!