0

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

  • `[Bind(Prefix = "ObjMemberInfo")]string Email` –  Dec 18 '17 at 08:11
  • @StephenMuecke i had already mentioned in question that the above answer dint worked for me,thats why i posted this again with my scenario –  Dec 18 '17 at 08:56
  • and i tried adding Bind with the Viewmodel reference but its still getting null value @StephenMuecke –  Dec 18 '17 at 08:56
  • Of course it works! Your current `[Bind]` attribute makes no sense –  Dec 18 '17 at 08:57
  • by following your suggested method i try adding like this public JsonResult CheckEmailExists_TeamMember([Bind(Prefix = "TeamMemberInfoViewModel")]string Email) –  Dec 18 '17 at 08:58
  • but it still sending the null value to the action –  Dec 18 '17 at 08:58
  • 1
    Read the 2nd answer in the dupe! Its `[Bind(Prefix = "ObjMemberInfo")]string Email` –  Dec 18 '17 at 08:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/161432/discussion-between-tamour-ali-and-stephen-muecke). –  Dec 18 '17 at 09:00

0 Answers0