asp.net-mvc - asp.net 远程属性验证
问题描述
这是我的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; }
}
这是我的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; }
}
User View model
我在我看来使用它
public class UserViewModel
{
public RegisterViewModel Register { get; set; }
public LoginViewModel Login { get; set; }
}
这是我的,View
我用我的UserViewModel
,我想validation Form
用这个Views
,它工作正常,但在我Controller
有一个JsonResult
动作并想检查电子邮件是否存在,问题是当我发送电子邮件以进行JsonResult
操作时它是空的
这是我的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>
}
这是我的JsonResult
操作,当我发送电子邮件时它是空的
public JsonResult IsExistEmail(string email)
{
return Json(!dbContext.KULLANICIs.Any(e => e.EMAIL == email), JsonRequestBehavior.AllowGet);
}
另外我的表格在popup modal
.
解决方案
推荐阅读
- asp.net-core - ASP.NET Core launchSettings.json 不启动浏览器
- macos - Outlook 2016 Mac:通过 AppleScript 将邮件移动到 Gmail 帐户中的文件夹
- python - 自动拆分具有异常字符的 CSV
- iis - 无法在 IIS 10.0 中将域用户名用作指定用户
- c# - 有没有办法要求在 C# 中密封派生类?
- jquery - 如果有子列表,则选择列出项目
- hibernate - 为什么hibernate在插入查询之前执行选择查询?
- django - Django URL 重定向和更改 URL 结构
- php - 连接phpmyadmin和html
- java - Java 中的负短路到 NDK 中的 uint16_t 处理不正确?