這是我的形式,我想調用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