gpt4 book ai didi

asp.net-mvc - valid()函数在jQuery表单验证MVC3中不起作用

转载 作者:行者123 更新时间:2023-12-02 03:39:47 26 4
gpt4 key购买 nike

我正在创建一个简单的mvc3应用程序。

意见是

<script>
function Submitform() {
var form = $('#frmAddStudent');
if (form) {
if (form.valid()) {
$(form).submit();
}
}
}
</script>

@using (Ajax.BeginForm("AddStudent", "Student", new AjaxOptions { HttpMethod = "POST" }, new { id = "frmAddStudent" }))
{
@Html.ValidationSummary(true)

<div class="editor-label">
@Html.LabelFor(model => model.StudentName)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.StudentName)
@Html.ValidationMessageFor(model => model.StudentName)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Address)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Address)
@Html.ValidationMessageFor(model => model.Address)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.DOB)
</div>
<div class="editor-field">
@Html.Telerik().DatePickerFor(model => model.DOB)
@Html.ValidationMessageFor(model => model.DOB)
</div>
<p>
<input type="button" value="Add" class="btn" onclick="return Submitform()" />
<input type="button" value="Cancel" class="close btn" onclick="closeDialog()" />
</p>
}

现在的问题是,当我单击“提交”按钮javascript函数调用时,它无法识别“form.valid()”函数。

它显示
form.valid()TypeError:form.valid不是函数

所以,这是什么问题。

最佳答案

尝试这个:

var form = $( "#frmAddStudent" );
form.validate();

function Submitform() {
if (form.valid()) {
$(form).submit();
}
}

关于asp.net-mvc - valid()函数在jQuery表单验证MVC3中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20800690/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com