I have an MVC3 application.
我有一个MVC3应用程序。
This is the model:
这是模型:
public class Customer
{
[Required]
public string Email { get; set; }
[Required]
public string Answer1 { get; set; }
[Required]
[NotEqualTo("Answer1")]
public string Answer2 { get; set; }
}
I enabled the onubtrusive validation on the web.config:
我在web.config上启用了onubtrusive验证:
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
And this on my _layout.cshtml:
这在我的_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>
My problem here is the MvcFoolproof is not working. The mvc data annotation validation Required
is working. What did I missed here? Thanks!
我的问题是MvcFoolproof无法正常工作。 mvc数据注释验证必需正在运行。我错过了什么?谢谢!
1 个解决方案
#1
1
First of all, I suppose you have included using Foolproof;
in your model.
首先,我想你已经包括使用Foolproof;在你的模型中。
Second, I believe you might need this script too (for client-side validation to work properly) <script src="/Scripts/MvcFoolproofJQueryValidation.min.js"></script>
.
其次,我相信您可能也需要此脚本(以便客户端验证正常工作)
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" />
.
第三,你是否使用NuGet添加了Foolproof包?您的packages.config应包含类似
Also, are you displaying any validation messages in the view? Are these being shown for the required properties, but not for the NotEqualTo
attribute?
此外,您是否在视图中显示任何验证消息?这些是显示所需的属性,但不是NotEqualTo属性?
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?
最后,您是否正确地在视图中显示所有这些属性,例如, @ Html.EditorFor(model => model.Answer1)?除非Answer2有比较的东西,否则肯定不会验证。你在表单上使用jQuery validate-call?
Mostly shots in the dark here, but getting Foolproof working is usually just a click-and-go operation.
大多数情况下在黑暗中拍摄,但获得万无一失的工作通常只是一次点击操作。
#1
1
First of all, I suppose you have included using Foolproof;
in your model.
首先,我想你已经包括使用Foolproof;在你的模型中。
Second, I believe you might need this script too (for client-side validation to work properly) <script src="/Scripts/MvcFoolproofJQueryValidation.min.js"></script>
.
其次,我相信您可能也需要此脚本(以便客户端验证正常工作)
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" />
.
第三,你是否使用NuGet添加了Foolproof包?您的packages.config应包含类似
Also, are you displaying any validation messages in the view? Are these being shown for the required properties, but not for the NotEqualTo
attribute?
此外,您是否在视图中显示任何验证消息?这些是显示所需的属性,但不是NotEqualTo属性?
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?
最后,您是否正确地在视图中显示所有这些属性,例如, @ Html.EditorFor(model => model.Answer1)?除非Answer2有比较的东西,否则肯定不会验证。你在表单上使用jQuery validate-call?
Mostly shots in the dark here, but getting Foolproof working is usually just a click-and-go operation.
大多数情况下在黑暗中拍摄,但获得万无一失的工作通常只是一次点击操作。