这是我的形式,我想调用Create ActionResut如果我不找到JSON结果方法的对象:如何在提交按钮ASP.NET调用preventDefault()后提交表单我试图调用提交功能在我的表单上,但没有什么我被困住?
@using (Html.BeginForm("Create", "InspekcijskeKontrole", FormMethod.Post, new { id = "forma1"}))
{ @ Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Inspekcijska kontrola</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.InspekcijskoTijeloId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("InspekcijskoTijeloId", null,"Odaberite inspekcijsko tijelo.....", new { @class = "form-control", @id="kombo3" })
@Html.ValidationMessageFor(model => model.InspekcijskoTijeloId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ProizvodId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("ProizvodId", null,"Odaberite proizvod.....", new { @class = "form-control", @id="kombo4" })
@Html.ValidationMessageFor(model => model.ProizvodId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DatumInspekcijskeKontrole, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DatumInspekcijskeKontrole, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DatumInspekcijskeKontrole, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Rezultat, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Rezultat, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Rezultat, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ProizvodSiguran, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<div class="checkbox">
@Html.EditorFor(model => model.ProizvodSiguran)
@Html.ValidationMessageFor(model => model.ProizvodSiguran, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="button" id="btnSave" value="Unesi" class="btn btn-success"/>
</div>
</div>
</div>
这我想在子表单提交之前执行的方法我使用e.preventDefault()来防止子提交此方法检查数据库中是否存在某些内容,但是如何返回sumbit,如何取消此e.preventDefault()如果值不存在执行提交事件不点击?
$("#btnSave").click(function(e){
e.preventDefault();
var zahtjev = $.getJSON("/InspekcijskeKontrole/Check?id1=" + $("#kombo3").val() + "&id2=" + $("#kombo4").val());
zahtjev.done(function (data) {
if (data.InspekcijskoTijeloId != -1 && data.ProizvodId != -1) {
$.getJSON("/Proizvodi/VratiIme/" + data.ProizvodId, function (ime) {
if (ime != null) {
$("#modalni1 p").text("Inspekcijska kontrola za " + ime + " je vec izvrsena");
$("#modalni1").modal({ backdrop: "static" });
}
});
}
});
zahtjev.fail(function (greska) {
$("#sp1").text(greska.responseText);
});
});
在'form'元素上调用'.submit()'? – David
不,它不工作我试过thx – jhony3
我没有看到任何*** ASP.Net ***在你的代码 - 甚至没有按钮服务器控制。 – Win