0

I am developing MVC project using c#. I have one model called EmployeeEducationDetails. Lets have a look at what I have created

public class EducationList
{
  public List<EmployeeEducationDetailTable> employeeEducationList { get; set; }

  public EducationList()
  {
    employeeEducationList = new List<EmployeeEducationDetailTable>();
  }

  public virtual EmployeeMainTable employee_MainTable { get; set; }
  public ICollection<EmployeeQualificationTypeTable> employee_QualficationTypeTable { get; set; }
}

public class EmployeeEducationDetailTable
{
  public int EmployeeId { get; set; }

  public int EmployeeEducationDetailId { get; set; }

  [Required(ErrorMessage = "Select qualification")]
  public int? EmployeeQualificationTypeId { get; set; }

  [Required(ErrorMessage = "Enter institute name")]
  public string EmployeeInstituteName { get; set; }

  [Required(ErrorMessage = "Enter year of pass")]
  public DateTime? EmployeeYearOfPass { get; set; }

  [Required(ErrorMessage = "Enter percentage")]
  public string EmployeePercentage { get; set; }
}

Until now I am not facing any problem. Our requirement needs to satisfy these conditions

  1. I have to design 4 division on same view like SSLC, PUC, DEGree, Post Degree using same model.
  2. Need to validate any one section among 4 divisions because education is mandatory for employee.
  3. If any data entered to any division then only it has to validate.

Please give me the idea about this. Your help would be greatly appreciated.

NOTE:here am passing List.Count to create 4 division dynamically and we have to use same model i.e. EducationList

  • What is that you are trying to validate? If you enter detail in any division means you are satisfying "Required" otherwise it would fail. Instead if you have any other validation criteria then you may bother this.. – Siva Gopal Dec 06 '14 at 06:08
  • Thank u for your comment above question assume am using EducationList Model as 4 List count 1 for sslc,1 for puc,1 for degree,And finally post degree .here I supposed to enter atleast one division and only entered division should be validate for example I if I studied only sslc am going to enter sslc division only and only sslc division should be validate ,,so requirement is I have to validate division only I have entered and atleast one division should be entered by user .finally as I said I only studied upto sslc then I will going to enter sslc only .rest divisions need not to validate – user3168867 Dec 06 '14 at 06:17
  • [Foolproof](http://foolproof.codeplex.com/) have some useful validation attributes that you can use. In your case, use view models and include a `bool` property and apply `[RequiredIfTrue]` to the other properties. –  Dec 06 '14 at 07:19
  • its working fine ;;but am using EducationList count how to validate if only particular bool property set to true. am facing problem in validation – user3168867 Dec 07 '14 at 06:18
  • If _its working fine_, what is your question? And what does `EducationList count` have do do with it. Did you try the `[RequiredIfTrue]` attribute? –  Dec 07 '14 at 07:52
  • Am sending 4 count to view of educationlist like employeeEducationList.Insert(1, new EmployeeEducationDetailTable()); employeeEducationList.Insert(2, new EmployeeEducationDetailTable()); employeeEducationList.Insert(3, new EmployeeEducationDetailTable()); employeeEducationList.Insert(4, new EmployeeEducationDetailTable()); finally am looping through on view and divided 4 section using if condition like if(I==1) then I made it has sslc so on – user3168867 Dec 09 '14 at 08:32

1 Answers1

0

If your design permits, you may provide a checkbox against each division and then use 'RequiredIf' Conditional Validation approach.

Please visit the following links to know more on this:

RequiredIf Conditional Validation Attribute

Flexible Conditional Validation ASP.NET MVC with Sample Code

Hope this help you.

Community
  • 1
  • 1
Siva Gopal
  • 3,474
  • 1
  • 25
  • 22