我正在执行从 mvc 视图到控制器的 post 函数,它工作正常并将数据插入数据库,但是当我尝试将 jsonresult 从控制器返回到视图时,它返回一个 http 403 禁止错误。我也尝试过直接访问该特定操作,它返回相同的 403 禁止错误。请问我哪里出错了?
控制器
<HttpPost()> _
Function Create(ByVal collection As ExternalMail) As JsonResult
Try
If ModelState.IsValid Then
_repositoryForExternalMail.Save(collection, "")
End If
Return Json(New ExternalMail With {.CostCentreCode = collection.CostCentreCode, .Day = collection.Day, .Quantity = collection.Quantity, .ExternalMailItemID = collection.ExternalMailItemID, .ExternalMailLocationID = collection.ExternalMailLocationID}, JsonRequestBehavior.AllowGet)
Catch
Return Json("An Error Occurred")
End Try
End Function
JSON
$(document).ready(function () {
var exturl = '@Url.Action("Create", "ExternalMail")';
$("#ExtMailCreate").click(function () {
var dataJSON = JSON.stringify(SaveExternalMail());
$.ajax({
type: "POST",
url: exturl,
data: dataJSON,
contentType: 'application/json; charset=utf-8',
success: function (data) {
showMessage("test", "information");
},
error: function (xhr, textStatus, errorThrown) {
$("#result").append(xhr.responseText);
$("#result").append(textStatus);
$("#result").append(errorThrown);
}
});
});
});