验证mvc提交按钮仅在有效时启用

时间:2013-06-18 07:34:55

标签: jquery asp.net-mvc data-annotations

我在我的模型上使用DataAnnotations并且JavaScript验证工作正常,但我现在需要在验证无效时禁用提交按钮

以下是我尝试使用的示例代码

<h2>
Index</h2>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>HomeModel</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.Description)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Description)
            @Html.ValidationMessageFor(model => model.Description)
        </div>
        <p>
            <input type="submit" value="Save" id="submit-button" />
        </p>
    </fieldset>
}<div>
@Html.ActionLink("Back to List", "Index")</div>@section Scripts {    @Scripts.Render("~/bundles/jqueryval")}

1 个答案:

答案 0 :(得分:-1)

你可以使用:

$("#myform").validate({
  success: function() {
    //here enable your button
  }
});