我正在从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);
}
});
});
});