但形式仍然是提交

但形式仍然是提交

本文介绍了MVC 4验证射击,但形式仍然是提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MVC 4验证工作,因为它似乎,错误消息弹出,但它仍然提交表单。任何想法,我缺少什么?谢谢你。

 公共类StatusRequestModel
{
    [需要]
    [显示(NAME =票号)]
    公众诠释? Tick​​etNumber {搞定;组; }    [需要]
    [显示(NAME =邮政code)]
    公众诠释?邮政code {搞定;组; }
}
@using(Html.BeginForm())
{
    @ Html.ValidationSummary()
    @ Html.LabelFor(X => x.TicketNumber)
    @ Html.TextBoxFor(X => x.TicketNumber)
    @ Html.LabelFor(X => x.Postal code)
    @ Html.TextBoxFor(X => x.Postal code)
    <输入类型=提交值=提交/>
    <输入类型=复位值=重置/>
}


解决方案

确保您已在code参考下列JS库:

 <脚本的src =@ Url.Content(〜/脚本/ jquery.validate.min.js)>< / SCRIPT>
<脚本的src =@ Url.Content(〜/脚本/ jquery.validate.unobtrusive.min.js)>< / SCRIPT>

确保您有以下的appSettings 在你的web.config文件中的条目:

 <添加键=ClientValidationEnabledVALUE =真/>
<添加键=UnobtrusiveJavaScriptEnabledVALUE =真/>

您还可以启用视图,而不是配置文件客户端验证,如果你想:

  @ {Html.EnableClientValidation(); }

My MVC 4 validation is working as it seems, the error messages pop up, but it still submits the form. Any idea what I am missing? Thank you.

public class StatusRequestModel
{
    [Required]
    [Display(Name = "Ticket Number")]
    public int? TicketNumber { get; set; }

    [Required]
    [Display(Name = "Postal Code")]
    public int? PostalCode { get; set; }
}


@using (Html.BeginForm())
{
    @Html.ValidationSummary()
    @Html.LabelFor(x => x.TicketNumber)
    @Html.TextBoxFor(x => x.TicketNumber)
    @Html.LabelFor(x => x.PostalCode)
    @Html.TextBoxFor(x => x.PostalCode)
    <input type="submit" value="Submit" />
    <input type="reset"  value="Reset"/>
}
解决方案

Ensure you have the following JS libraries referenced in your code:

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script>

Ensure you have the following appSettings entries in your web.config file:

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

You can also enable client validation in the view instead of the config file if you wish:

@{ Html.EnableClientValidation(); }

这篇关于MVC 4验证射击,但形式仍然是提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 14:53