I have been attempting to use ASP.NET MVC remote validation for username login access to return both a string and a boolean. If I return just a string, it will assume a boolean of false and not let the user submit the form. Is there a way I could pass in both true and a string such as “[USERNAME] is available!”?
Current method:
public JsonResult isUserAvailable(string username)
{
if (Membership.GetUser(username) == null)
{
return Json(String.Format(CultureInfo.InvariantCulture, "<strong style='color: green;'>{0} is available!</strong>",
username), JsonRequestBehavior.AllowGet);
}
else
{
return Json(false, JsonRequestBehavior.AllowGet);
}
}
As @Furqan suggested the data you are returning is not Json but Html.
I suggest that you either return a Json object or a different ActionResult, perhaps
ContentResult. This blog post does a good job of explaining the differentActionResulttypes.