javascript - 如何将 Id 赋予 @using (Ajax.BeginForm("Index", "Customer", FormMethod.Post, new AjaxOptions(){})){....}
问题描述
我正在做一个 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(){})){ /* ... */}
另一个问题是,有没有更好的方法在表单提交时禁用提交按钮,并在表单提交完全没有问题时再次启用按钮?
解决方案
您调用的方法签名的第 5 个参数Ajax.BeginForm()
是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...
}
推荐阅读
- android - Android InApp 购买不同位置
- java - 如何通过单击暂停音频文件并开始一个新文件?
- javascript - 当我的查询错误时,getColors.php 不会发出此通知
- excel - 检测excel单元格中分隔值内的重复
- c# - Unity 是否将脚本编译为 C++?
- laravel - 迁移后在迁移列表中添加迁移文件
- json - VB.NET JSON POST 请求中的错误 - HTTPWEBREQUEST
- javascript - 如何为每条记录创建嵌套网格的动态列
- tcl - 将一个列表拆分为多个子列表,更改一个特定的子列表,然后重新加入所有子列表以形成一个新列表?
- android - xml 内容不正确