我有以下代码包含验证:
<div id="ContactDialog" style="display: none;">
@Html.LabelFor(model => model.subject)
@Html.TextBoxFor(model => model.subject, new { @class = "AboutControls" })
@Html.ValidationMessageFor(model => model.subject)
<br /><br />
@Html.LabelFor(model => model.from)
@Html.TextBoxFor(model => model.from, new { @class = "AboutControls" })
@Html.ValidationMessageFor(model => model.from)
<br /><br />
@Html.LabelFor(model => model.body)
@Html.TextAreaFor(model => model.body, new { @class = "AboutControls" })
@Html.ValidationMessageFor(model => model.body)
<hr />
<br /><br />
</div>
此代码从JQuery ajax代码执行。因此,不会触发验证。所有字段都是必需的,但由于它们不是通过<input type="submit" value="..." />
调用的,因此不会触发验证,即使它们为空,它们也会通过,从而导致异常。即使没有使用<input ... />
,我怎样才能确保触发验证?