简体   繁体   English

ASP.NET MVC:不会触发远程验证

[英]ASP.NET MVC: Remote Validation not fired

Having problem calling the remote validation. 调用远程验证时遇到问题。 I have everything setting properly with the matching property name with argument in the remoting methods in my controller. 我在控制器的远程处理方法中使用匹配的属性名称和参数正确设置了所有设置。 Only thing I suspect was the model which I located in a separate project. 我唯一怀疑的是我位于单独项目中的模型。

This is my code of the model: 这是我的模型代码:

[Display(Name="First name")]
    [Required(ErrorMessage="First name required")]
    public string Firstname { get; set; }

    [Display(Name = "Last name")]
    [Required(ErrorMessage = "Last name required")]
    public string Lastname { get; set; }

    [Display(Name = "Username")]
    [Required(ErrorMessage = "Username required")]
    [Remote("IsUsernameExisted", "UserValidationController", HttpMethod = "POST")]
    public string Username { get; set; }

    [Display(Name = "Email address")]
    [Required(ErrorMessage = "Email address required")]
    [Remote("IsEmailExisted", "UserValidationController", HttpMethod = "POST")]
    public string EmailAddress { get; set; }

    [Display(Name = "Password")]
    [Required(ErrorMessage = "Password required")]
    public string Password { get; set; }

    [Display(Name = "Confirmation password")]
    [Required(ErrorMessage = "Confirmation required")]
    [System.Web.Mvc.CompareAttribute("Password", ErrorMessage = "Passwords don't match.")]
    public string ConfirmationPassword { get; set; }

This model is a separate project but in same solution in visual studio. 该模型是一个单独的项目,但在Visual Studio中使用相同的解决方案。

Will it the reason the remote validation not get fired. 请问这是没有触发远程验证的原因。

Might be this missing in your web.config? 您的web.config中可能会丢失吗?

  <appSettings>
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>

" Because no JavaScript is emitted when you use unobtrusive client validation, if you forget to include the validation scripts, you will not see any errors when the page loads. The only result is that the form values will not be validated in the browser. " 由于使用无干扰的客户端验证时不会发出JavaScript,因此,如果忘记包括验证脚本,则在页面加载时将不会看到任何错误。唯一的结果是,表单值不会在浏览器中得到验证。

Source: How to: Implement Remote Validation in ASP.NET MVC 来源: 如何:在ASP.NET MVC中实现远程验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM