【发布时间】:2015-01-27 16:33:06
【问题描述】:
这是我点击按钮的 ajax 代码。警报框显示值是正确的。但是当它试图去控制器它给我一个 500 错误。控制器是 ContentPackController。
$(function () {
$('#updateContent').click(function () {
var selectedValue = $('#contentAlias').val();
var value = $('#contentPackDetails').val();
alert(selectedValue + " " + value);
$.ajax({
url: '@Url.Action("UpdateContent", "ContentPack")',
type: "POST",
data: { PropId: selectedValue, UpdateText: 'Looking For An <span class="embellish">Great Deal</span> On Your Next Home?"' },
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}, success: function () {
alert("Updates have been saved");
}
});
});
});
这是应该调用的 ActionResult
public ActionResult UpdateContent(int PropId, string UpdateText)
{
using (var entities = new OpenRoadEntities())
{
var prop = entities.ContentPackDetails.FirstOrDefault(c => c.Id==PropId);
prop.Value = UpdateText;
entities.SaveChanges();
return Json(new EmptyResult(),JsonRequestBehavior.AllowGet);
}
}
这简直快把我逼疯了。对同一控制器的其他调用正常工作。
【问题讨论】:
-
您正在发出 POST 请求,并且该操作看起来像是为 GET 设置的。
-
你的 apache 错误日志是怎么说的?
-
@PaulAbbott 它甚至没有采取行动。它仍然应该达到不应该的功能吗?
-
它不会影响您的操作,因为它没有被装饰为
[HttpPost]。默认情况下(未修饰)是[HttpGet]。
标签: jquery ajax asp.net-mvc