I'm trying to use remote validation to make sure an input has a value but only when a previous input has a specific value. However, the remote validation is not being hit.
I have put a break point on the remote validation action in the controller and that is never hit.
This is in my model:
[Remote("_Validate_Show", "Validation", AdditionalFields = "Group_Id,Dev_Group_Id", ErrorMessage = "Please select an option")]
public bool? Show { get; set; }
This is my controller:
public class ValidationController
{
public JsonResult _Validate_Show(bool? Show, Guid? Group_Id, Guid Dev_Group_Id)
{
if (!Show.HasValue && Group_Id.HasValue && Group_Id == Dev_Group_Id)
{
return base.Json(false, JsonRequestBehavior.AllowGet);
}
return base.Json(true, JsonRequestBehavior.AllowGet);
}
}
And this is what I have in my View:
<div>@Html.ExtendedDropDownListFor(model => model.Group_Id, Model.Group_Ids)</div>
<div>@Html.DropDownListFor(model => model.Show, Model.Show_Options)</div>
<div>@Html.ValidationMessageFor(model => model.Show)</div>
Basically if the 'Group_Id' is the 'Dev_Group_Id' then 'Show' must have a value but if the 'Group_Id' is not the 'Dev_Group_Id' then 'Show' can be null.
I even tried to simplify it and remove the additional fields so it just checked the 'Show' value but again the action in the controller was never hit.
I can also confirm that I have these scripts in my view:
<script src="@Url.Content("~/Scripts/jquery.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script>