0

Ok i have this Edit form, what i need is some kind of custom validation for when i enter ReturnDate it Shouldn't be lower then the date of IssueDeadLineDate value. Can i do with Some kind of custom validation or what do i need ?

Edit View Picture

  namespace Library.Models
 {
  public class BookStatusView
  {
    public int Id { get; set; }
    public string UserId { get; set; }
    public DateTime IssueDeadlineDate { get; set; }
    public DateTime ReturnDeadlineDate { get; set; }

    public DateTime? ReturnDate { get; set; }
    public int BookId { get; set; }
    public string AspNetUser { get; set; }
    public string BookName { get; set; }


    public IEnumerable<SelectListItem> qwerty { get; set; }

    public string Email { get; set; }
    public string FirstName { get; set; }

This is my BookStatusView model where i want to implement custom validation. If u need any other code feel free to ask i will paste it ass soon as i see it.

  • http://stackoverflow.com/questions/8906228/how-to-validate-one-field-related-to-anothers-value-in-asp-net-mvc-3 – maccettura Apr 04 '17 at 18:44
  • You could write a custom validation attribute: https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.customvalidationattribute(v=vs.95).aspx or on stack: http://stackoverflow.com/questions/23780943/how-to-create-custom-validation-attribute – freshbm Apr 04 '17 at 18:44
  • ty for fast asnwers, 1 more question did anyone tried this MVC FoolProof Validation framework maybe ? – Andrija valusek Apr 04 '17 at 18:56

1 Answers1

1

if you are looking to do server side validation you can do a simple comparison

if(ReturnDate < IssueDeadlineDate) in the controller

if you are wanting client side validation you will need to compare the model values in a similar way but in javascript

You could also try using a custom ValidationAttribute

http://dotnetmentors.com/mvc/how-to-do-custom-validation-using-validationattribute-of-aspnet-mvc.aspx