Vondella21:
i tried to to validate my Username remotely ,unfortunately is not firing here are my codes for viewmodel
public class UsersNew
{
public IListRoles { get; set; }
[Required,StringLength(6,MinimumLength =3)]
[Remote("IsAvailable","Validation")]
[RegularExpression(@"(\S)+",ErrorMessage = "White space is not allowed.")]
public string username { get; set; }
[Required,DataType(DataType.Password)]
public string password { get; set; }
[Required,MaxLength(256),DataType(DataType.EmailAddress)]
public string email { get; set; }
}
my controller
public class ValidationController : Controller
{
public JsonResult IsAvailable(string username)
{
if (!Database.Session.Query().Any(u => u.username == username))
return Json(true, JsonRequestBehavior.AllowGet);
string suggestedUID = String.Format(CultureInfo.InvariantCulture, "{0} is
not available ", username);
for (int i = 0; i {
string altCandidate = username + i.ToString();
if (!Database.Session.Query().Any(u => u.username == altCandidate))
{
suggestedUID = string.Format(CultureInfo.InvariantCulture, "{0} is not
available. Try {1}", username,
altCandidate);
break;
}
}
return Json("error", JsonRequestBehavior.AllowGet);
}
}
i even include default jquery validation
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
what am i doing wrong here?
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE