MVC万全不工作的MVC3 [英] Mvc Foolproof not working on mvc3

查看:148
本文介绍了MVC万全不工作的MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC3应用程序

I have an MVC3 application.

这是模型:

public class Customer
{
    [Required]
    public string Email { get; set; }

    [Required]
    public string Answer1 { get; set; }

    [Required]
    [NotEqualTo("Answer1")]
    public string Answer2 { get; set; }
}



我启用在web.config中的onubtrusive验证:

I enabled the onubtrusive validation on the web.config:

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

和这对我_layout.cshtml:

And this on my _layout.cshtml:

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script src="@Url.Content("~/Scripts/mvcfoolproof.unobtrusive.js")" type="text/javascript"></script>



我的问题是MvcFoolproof不工作。 MVC的数据注解验证要求正在工作。做什么我错过了吗? !谢谢

My problem here is the MvcFoolproof is not working. The mvc data annotation validation Required is working. What did I missed here? Thanks!

推荐答案

首先,我想你已经包括使用万无一失; 在模型

First of all, I suppose you have included using Foolproof; in your model.

第二,我相信你可能需要这个剧本太(用于客户端验证才能正常工作)<脚本SRC =/脚本/ MvcFoolproofJQueryValidation.min.js>< / SCRIPT>

Second, I believe you might need this script too (for client-side validation to work properly) <script src="/Scripts/MvcFoolproofJQueryValidation.min.js"></script>.

三,你有没有加入万全包使用的NuGet?你的 packages.config 应该包含这样的<包ID =万无一失版本=0.9.4517targetFramework =net45/>

Third, did you add the Foolproof package using NuGet? Your packages.config should contain something like <package id="foolproof" version="0.9.4517" targetFramework="net45" />.

此外,你在显示视图任何验证消息?难道这些被显示为所需的属性,而不是为 NotEqualTo 属性?

Also, are you displaying any validation messages in the view? Are these being shown for the required properties, but not for the NotEqualTo attribute?

最后,你显示所有在视图这些属性正确,例如使用 @ Html.EditorFor(型号=> model.Answer1)?除非有ANSWER2东西比较,它肯定不会验证。而你正在使用的表单上的jQuery验证呼叫?

Last, are you displaying all those properties in the view correctly, using e.g. @Html.EditorFor(model => model.Answer1)? Unless Answer2 has something to compare to, it surely won't validate. And you're using the jQuery validate-call on the form?

拍摄大多在这里暗,但得到万全的工作通常只需点击和去操作

Mostly shots in the dark here, but getting Foolproof working is usually just a click-and-go operation.

这篇关于MVC万全不工作的MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆