Friday 19 February 2021

MVC - Custom Validation - Remote - Additional Fields - Display dynamic error message

 Watch on YouTube


 Replace 

       public ActionResult ValidateSalary(Customer c)
        {
            string Salary = c.Salary.ToString();
            string res = db.ValidateOnDBSide(Convert.ToInt32(Salary)).FirstOrDefault();
            if(res != string.Empty)
            {
                return Json(false, JsonRequestBehavior.AllowGet);
            }
            return Json(true, JsonRequestBehavior.AllowGet);
        }

with

       public ActionResult ValidateSalary(Customer c)
        {
            string Salary = c.Salary.ToString();
            string res = db.ValidateOnDBSide(Convert.ToInt32(Salary)).FirstOrDefault();
            if(res != string.Empty)
            {
                return Json(res, JsonRequestBehavior.AllowGet);
            }
            return Json(true, JsonRequestBehavior.AllowGet);
        }

No comments:

Post a Comment