我正在创建一个简单的mvc3应用程序。
VIew
<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不是函数
所以,问题就是这个。
答案 0 :(得分:1)
试试这个:
var form = $( "#frmAddStudent" );
form.validate();
function Submitform() {
if (form.valid()) {
$(form).submit();
}
}