我想通过models属性完成的客户端验证来停止表单提交。我已经完成了各种可能性但是成功了......请看这段代码:
我的模特是
[Key]
public int User_ID { get; set; }
[Required(ErrorMessage = "* Please Enter FirstName")]
public string User_FN { get; set; }
[Required(ErrorMessage = "* Please Enter MiddleName")]
public string User_MN { get; set; }
[Required(ErrorMessage = "* Please Enter LastName")]
public string User_LN { get; set; }
[Required(ErrorMessage = "* Please Enter LoginID")]
public string User_Login { get; set; }
[Required(ErrorMessage = "* Please Enter PassWord")]
public string User_Password { get; set; }
[Required(ErrorMessage = "* Please Select a Valid Role")]
public int User_Role_ID { get; set; }
[Required(ErrorMessage = "* Please Select any one Table")]
public List<int> Table_ID { get; set; }
[Required]
public List<bool> P_Add { get; set; }
[Required]
public List<bool> P_Edit { get; set; }
[Required]
public List<bool> P_Delete { get; set; }
我添加了这个引用jquery文件
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
并将这些键设置为
<appSettings>
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
所有设置完成但页面仍然提交...请建议我
答案 0 :(得分:0)
您需要在validate.unobtrusive.min.js
之前加载validate.js