当我点击提交按钮什么都不做时,说没有定义BorcEkle在HTML中调用哪一个。 我用于指导另一个MVC Web App,他们这样称呼,并且它有效。
BorcEkle.cshtml 提交Button和JS
function BorcEkle() {
if ($("#aciklama").val() == null || $("#hesap").val() == null || $("#tutar").val() == null || $("#start").val() == null || $("#end").val() == null || $("#e12").val() == null) {
new PNotify({
title: 'Ups!',
text: 'Lütfen alanları doldurunuz.',
type: 'error',
icon: 'ti ti-close',
styling: 'fontawesome'
});
} else {
new PNotify({
title: 'Borç Eklendi',
text: 'Borç verisi başarılyla eklendi.',
type: 'success',
icon: 'ti ti-check',
styling: 'fontawesome'
});
$.post("@Url.Action("BorcEkle", "Dashboard")", {
aciklama: $("#aciklama").val(),
hesap: $("#hesap").val(),
tutar: $("#tutar").val(),
start: $("#start").val(),
end: $("#end").val(),
kategori: $("#e12").val()
}, function(data) {
new PNotify({
title: 'Borç Eklendi',
text: 'Borç verisi başarılyla eklendi.',
type: 'success',
icon: 'ti ti-check',
styling: 'fontawesome'
}).then(function() {
location.reload();
}, function(dismis) {
if (dismis == 'cancel' || dismis == 'overlay') {
location.reload();
}
});
});
}
}

<button type="submit" class="btn-primary btn" method="post" onclick="BorcEkle()">Kaydet</button>
&#13;
DashboardController.cs
[HttpPost]
public ActionResult BorcEkle(string aciklama, string hesap, decimal tutar, DateTime start, DateTime end , string kategori)
{
var addDebt = new TBLADDDEBT();
addDebt.EXPLANATION = aciklama;
addDebt.BILLACCUNT = hesap;
addDebt.AMOUNT = tutar;
addDebt.DATEOFISSUE = start;
addDebt.DUEDATE = end;
addDebt.TBLCATEGORY.CATEGORYNAME = kategori;
addDebt.CATEGORYID = addDebt.TBLCATEGORY.CATEGORYID;
addDebt.ISACTIVE = true;
addDebt.REGDATE = DateTime.Now;
addDebt.USERID = SessionModel.Current.User.USERID;
//addDebt.EXPLANATION = form["Aciklama"].Trim();
//addDebt.BILLACCUNT = form["Hesap"].Trim();
//addDebt.AMOUNT = Convert.ToDecimal(form["Hesap"].Trim());
//addDebt.DATEOFISSUE = Convert.ToDateTime(form["daterangepicker_start"]);
//addDebt.DUEDATE = Convert.ToDateTime(form["daterangepicker_end"]);
//addDebt.TBLCATEGORY.CATEGORYNAME = form["Kategori"];
db.TBLADDDEBT.Add(addDebt);
db.SaveChanges();
return View();
}