0

here is my Register View Model

 public class RegisterViewModel
{

    [Required(AllowEmptyStrings = false, ErrorMessage = "Bu alanı boş bırakmayınız.")]
    public string ADI { get; set; }

    [Required(AllowEmptyStrings = false, ErrorMessage = "Bu alanı boş bırakmayınız.")]
    [DataType(DataType.Password)]
    [MinLength(6, ErrorMessage = "Parola en az 6 karakter olmalıdır!")]
    public string PAROLA { get; set; }

    [DataType(DataType.Password)]
    [System.ComponentModel.DataAnnotations.Compare("PAROLA", ErrorMessage = "Şifre Eşleşmedi!")]
    public string PAROLA_DOGRULA { get; set; }

    [Required(AllowEmptyStrings = false, ErrorMessage = "Bu alanı boş bırakmayınız.")]
    [RegularExpression(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Yanlış mail,Lütfen doğru mail Giriniz")]
    [Remote("IsExistEmail", "Account", ErrorMessage = "Bu email daha önce kullanımıştır")]
    public string EMAIL { get; set; }

    [Required(AllowEmptyStrings = false, ErrorMessage = "Bu alanı boş bırakmayınız.")]
    public string SOYADI { get; set; }
}

And Here is my login View Model

public class LoginViewModel
{
    [Required(AllowEmptyStrings = false, ErrorMessage = "Bu alanı boş bırakmayınız.")]
    [DataType(DataType.Password)]
    [Remote("CheckLoginPassword", "Account",ErrorMessage ="Girdiğiniz Email kayıtlarımızda bulunamadı.")]
    public string PAROLA { get; set; }

    [Required(AllowEmptyStrings = false, ErrorMessage = "Bu alanı boş bırakmayınız.")]
    [RegularExpression(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Yanlış mail,Lütfen doğru mail Giriniz")]
    [Remote("CheckLoginMail", "Account", ErrorMessage = "Bu email daha önce kullanımıştır")]
    public string EMAIL { get; set; }
}

and User View model i use it in my view

 public class UserViewModel
{
    public RegisterViewModel Register { get; set; }
    public LoginViewModel Login { get; set; }
}

here is my View i use my UserViewModel and i want to validation Form with this Views,its work fine but in my Controller i have A JsonResult Action and want to check if Email is Exist or not,Problem is when i send the email for JsonResult action its is null

here is my View

@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @id = "registerForm" }))
                                            {
                                                @Html.ValidationSummary(true)


                                                @Html.ValidationMessage("RegisterErrors", new { @class = "ValidationErrorMessageColor" })

                                                @Html.EditorFor(model => model.Register.ADI, new { htmlAttributes = new { required = "", @class = "myRegisterInput", placeholder = "Ad" } })
                                                @Html.ValidationMessageFor(model => model.Register.ADI, "", new { @class = "ValidationErrorMessageColor" })

                                                @Html.EditorFor(model => model.Register.SOYADI, new { htmlAttributes = new { required = "", @class = "myRegisterInput", placeholder = "Soyad" } })
                                                @Html.ValidationMessageFor(model => model.Register.SOYADI, "", new { @class = "ValidationErrorMessageColor" })

                                                @Html.EditorFor(model => model.Register.EMAIL, new { htmlAttributes = new { required = "", @class = "myRegisterInput", placeholder = "Email" } })
                                                @Html.ValidationMessageFor(model => model.Register.EMAIL, "", new { @class = "ValidationErrorMessageColor" })

                                                @Html.EditorFor(model => model.Register.PAROLA, new { htmlAttributes = new { required = "", @class = "myRegisterInput", placeholder = "Parola" } })
                                                @Html.ValidationMessageFor(model => model.Register.PAROLA, "", new { @class = "ValidationErrorMessageColor" })

                                                @Html.EditorFor(model => model.Register.PAROLA_DOGRULA, new { htmlAttributes = new { required = "", @class = "myRegisterInput", placeholder = "Parolayı onayla" } })
                                                @Html.ValidationMessageFor(model => model.Register.PAROLA_DOGRULA, "", new { @class = "ValidationErrorMessageColor" })

                                                <div class="sign-up">
                                                    <input type="submit" value="Hesap oluştur" />
                                                </div>
                                            }

and here is my JsonResult Action,when i send the email it's Null

 public JsonResult IsExistEmail(string email)
    {
        return Json(!dbContext.KULLANICIs.Any(e => e.EMAIL == email), JsonRequestBehavior.AllowGet);
    }

in addition my form is on the popup modal .

  • Because you are sending a value for `Login.EMAIL`, not `EMAIL` (you could change it to `IsExistEmail([Bind(Prefix = "Login")]string email)` - but it makes no sense to include both the Register and Login elements in the one view) –  Aug 06 '18 at 12:07
  • i do it but it's still null – murtaza safar Aug 06 '18 at 12:15
  • You also need to do the same for Register (i.e `Bind(Prefix = "Register")]`) –  Aug 06 '18 at 12:18
  • I'm sorry but it's not work – murtaza safar Aug 06 '18 at 12:31
  • Then try `Bind(Prefix = "Register.EMAIL")` - but again you are going about this the wrong way –  Aug 06 '18 at 12:33

0 Answers0