Please, read this article, that gives a full explanation of how remote validation works. Pay special attention to this lines:
Any response other than true is considered false
So if your JSON is different from true, it's regarded as being an error. And, if is an string, it will be shown as the error message on the clien side.
So, your remote valdiation action should return:
- either
true
, if it's correct - or an string with the error message, which will be shown in the browser
If you return anything else, it will be regarded as error, but the message will be lost. If you wnat a fixed error message, return that string from the validation action in your controller.
So your action must return a JsonResult
, you can return what you need:
if (valid)
{
return Json(true);
}
else
{
return Json("this is the error message");
}