I want to Check whether the master type already exists or not using remote validation.
In my case the remote validation method is not firing.Can anyone help me?
Model
[Key, Column(Order = 1)]
[StringLength(200)]
[Display(Name = "MasterType")]
[Remote("IsNameAvailable", "MasterSetUps", ErrorMessage = "Master type already exists ")]
public string MasterType { get; set; }
Validation Method
[AllowAnonymous]
public JsonResult IsNameAvailable(string MasterType)
{
bool result = true;
if (s_mode == "ADD")
{
return Json(!db.MasterSetUps.Any(a => a.MasterType == MasterType), JsonRequestBehavior.AllowGet);
}
else if (s_mode == "EDIT" & MasterType != s_Master_Type_name)
{
return Json(!db.MasterSetUps.Any(a => a.MasterType == MasterType), JsonRequestBehavior.AllowGet);
}
return Json(result, JsonRequestBehavior.AllowGet);
}
View
<div class="form-group">
@Html.LabelFor(model => model.MasterType, htmlAttributes: new { @class = "control-label col-sm-2" })
<div class="col-sm-10">
@Html.DropDownList("MasterType", null, htmlAttributes: new { @class = "form-controls" })
@Html.ValidationMessageFor(model => model.MasterType, "", new { @class = "text-danger" })
</div>
</div>
GetMethod
public ActionResult Create()
{
s_mode = "ADD";
ViewBag.MasterType = new SelectList(db.Masters, "MasterType", "MasterType");
return View();
}