使用剃须刀验证而不提交表格

时间:2016-04-30 07:51:55

标签: javascript jquery asp.net-mvc razor

在我看来,我有以下代码:

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @id = "searchInvoiceForm", @class = "form-inline" }))
{

    @Html.Label("Numer faktury", new { @class = "margin-top-10" })
    @Html.TextBox("invNumber", "", new { @class = "input-sm form-control margin-right-10 margin-left-20", @type = "number", @min = "0" })
    ...
    <button id="searchForInvoicesButton" class="btn margin-top-10 margin-bottom-10">Szukaj</button>
}

所以我想用这个&#34; razor-style&#34;验证类似于&#34; @type =&#34; number&#34;,@ min =&#34; 0&#34;&#34;,但我的javascript中的提交按钮被禁止进行默认操作。我试过像

这样的东西
var form = $('#searchInvoiceForm');
if (form.valid()) {
...

但它似乎永远不会通过验证。我的表单中还有其他几个文本框,但这只需要一个,并且有一些限制,如number和minValue。有没有办法让它发挥作用?

0 个答案:

没有答案