我使用MVC 4,我尝试使用ajaxsumbit提交表单,它的工作原理!但现在,在带有ajaxsubit的sumbit表格后,我想禁用一些输入:
控制器:
//
// POST: /Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(DadosComerciais dados)
{
if (ModelState.IsValid)
{
db.DadosComerciais.Add(dados);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(dados);
}
查看:
@using (Html.BeginForm("Create", "Contrato", FormMethod.Post, new { id="formContrato"}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<table>
<tr>
<td>Série: </td>
<td>@Html.DropDownList("Serie", new List<SelectListItem>(), new { @class = "form-control input-sm", onchange = "NumDocContrato(this)"})
</td>
</tr>
</table>
}
和js文件:
function saveContrato()
{
//Guardar os dados comerciais para os contratos
//$("#formContrato").submit();
$("#formContrato").ajaxSubmit({
type: "post",
url: $("#formContrato").attr("action"),
clearForm: false,
success:
$("#Serie").prop("disabled", "disabled")
});
$("#formContrato").submit(function () {
return false;
});
$("#DefinirEstab").attr("onclick", "CountEstab()");
}
答案 0 :(得分:0)
首先将Serie
ID分配给您的下拉列表。
@Html.DropDownList("Serie", new List<SelectListItem>(), new { id = "Serie", @class = "form-control input-sm", onchange = "NumDocContrato(this)"})
更改:
$("#Serie").prop("disabled", "disabled")
要:
success: function () {
$("#Serie").prop("disabled", true)
}