check answer here[
^]
validation in db first[
^]
Please these two links, you will surely get your answer.
The issue is with the model, not the view.
Check and try.
[HttpPost]
public ActionResult Login(LoginViewModel viewModel)
{
if (ModelState.IsValid)
{
return RedirectToAction("Index", "Home");
}
if (string.IsNullOrEmpty(viewModel.UserName))
{
ModelState.AddModelError("UserName", "Name is required");
}
if (!string.IsNullOrEmpty(model.Email))
{
string emailRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(emailRegex);
if (!re.IsMatch(model.Email))
{
ModelState.AddModelError("Email", "Email is not valid");
}
}
else
{
ModelState.AddModelError("Email", "Email is required");
}
return View(viewModel);
}
ASP.NET MVC Client Side Validation[
^]
Post back ur comments with queries if any.
Thanks