如何将ID赋予@using(Ajax.BeginForm(“ Index”,“ Customer”,FormMethod.Post,new AjaxOptions(){})){....}

时间:2019-07-02 16:23:10

标签: javascript c# jquery asp.net-mvc

我正在做一个asp.net mvc项目,我想在表单使用以下jquery代码提交时禁用所有提交按钮:

$(function()
{
  $('#theform').submit(function(){
    $("input[type='submit']", this)
      .val("Please Wait...")
      .attr('disabled', 'disabled');
    return true;
  });
});

我的表单如下:

@using (Ajax.BeginForm("RegisterCustomer", "Customer", FormMethod.Post, new AjaxOptions()
{
    OnSuccess = "success",
    UpdateTargetId = "listUsers"

}))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <div class="form-group has-feedback">
        @Html.EditorFor(model => model.identificationNo, new {htmlAttributes = new {@class = "form-control", placeholder = Html.DisplayNameFor(x => x.identificationNo)}})
        @Html.ValidationMessageFor(model => model.identificationNo, "", new {@class = "text-danger"})
    </div>

    <div class="form-group has-feedback">
        @Html.DropDownListFor(model => model.identificationType, new SelectList(itemsOfIdentificationType, "Key", "Value"), "نوع شناسه را انتخاب نمایید", new {style = "width:315px; height: 30px; padding 5px; margin: 5px 0 6px; background: none repeat scroll 0 0 #FFFFFF; vertical-align:middle;"})
        @Html.ValidationMessageFor(model => model.identificationType, "", new {@class = "text-danger"})
    </div>
        <div class="row">
            <div class="col-xs-12">
                <button class="btn btn-primary btn-block btn-flat" type="submit">Register</button>
            </div>
        </div>
}

如何将ID赋予:

@using (Ajax.BeginForm("Index", "Customer", FormMethod.Post, new AjaxOptions(){})){ /* ... */}

另一个问题是,有什么更好的方法可以在表单提交时禁用提交按钮,而在表单完全提交而没有任何问题时再次启用按钮?

1 个答案:

答案 0 :(得分:0)

您要为Ajax.BeginForm()调用的方法签名的第5个参数是htmlAttributes对象,您可以像这样提供:

@using (Ajax.BeginForm(
  "Index", 
  "Customer", 
  FormMethod.Post, 
  new AjaxOptions() { /* your options */ },
  new { @Id = "theform" } /* HTML attributes can be placed in this object */
))
{
  // form controls here...
}