I am using custom fluent validation and modal popup having controls. Only the required field validator is displaying error message on submit. How to return custom error message on to the same modal popup.
Model
RuleFor(x => x.Participants)
.NotEmpty()
.WithMessage("Please Select Participant.")
.Must(IsChaimanPresentValidator)
.WithMessage("Director type with 'Chairman' is required in Participant");
private bool IsChaimanPresentValidator(string directorTypeList)
{
if (directorTypeList != null)
{
string[] directorTypes = directorTypeList.Split(',');
string directorType = (DirectorType.Chairman).ToString();
if (directorTypes.Contains(directorType))
{
return true;
}
else
{
return false;
}
}
return true;
}
Controller
public ActionResult Create()
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageMeeting))
return AccessDeniedPublicView();
MeetingModel objMeetingModel = new MeetingModel();
try
{
objMeetingModel.Id = 0;
objMeetingModel.CompanyList = _companyService.GetAllCompanies().Select(x => x.ToModel()).ToList();
objMeetingModel.MeetingTypeList = getMeetingType();
objMeetingModel.MeetingStatusList = getMeetingStatus();
}
catch (Exception ex)
{
LogException(ex);
}
ViewBag.IsEditPage = false;
return PartialView("_Create",objMeetingModel);
}
[HttpPost]
public ActionResult Create(MeetingModel meetingmodel)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageMeeting))
return AccessDeniedPublicView();
try
{
if (!ModelState.IsValid)
{
var allErrors = ModelState.Values.SelectMany(v => v.Errors);
return Json(new { success = false, Errors = ModelState.SerializeErrors() });
}
}