I am trying to validate email existence by using Remote validation.I have searched this on Stack-overflow but no answer works for me. The value sent to Validation method is null. Here is the Html form..
<div class="form-group">
<label>Email</label>
@Html.TextBoxFor(m => m.ObjMemberInfo.Email, new { @class = "form-control regcom", @placeholder = "Enter E-mail", maxlength = 45 })
@Html.ValidationMessageFor(m => m.ObjMemberInfo.Email, "", new { @style = "color:red" })
</div>
Here is the action i am calling.
public JsonResult CheckEmailExists_TeamMember([Bind(Prefix = "AreaTeamManagementViewModel.TeamMemberInfoViewModel.Email")]string Email)
{
bool UserExists = false;
try
{
var nameexits = db.UsersRegistrations.Where(m => m.Email == Email && m.Deleted != true && m.UserRole.RoleType == "TeamMember").ToList();
if (nameexits.Count > 0)
{
UserExists = true;
}
else
{
UserExists = false;
}
return Json(!UserExists, JsonRequestBehavior.AllowGet);
}
catch (Exception)
{
return Json(false, JsonRequestBehavior.AllowGet);
}
}
Here is the ViewModel
[RegularExpression(@"^([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})(\]?)$", ErrorMessage = "Please enter a valid e-mail adress")]
[System.Web.Mvc.Remote("CheckEmailExists_TeamMember", "TeamManagement", ErrorMessage = "Team Member With Same Email Already Exist!")]
[Required(ErrorMessage = "Email is Required")]
public string Email { get; set; }
kindly suggest me any way to resolve this.Thanks