I am doing a post function from a mvc view to the controller which works fine and inserts the data into the database but when i try to return the jsonresult from the controller to the view, it returns a http 403 forbidden error. i have also tried accessing that particular action directly and it's returning the same 403 forbidden error. any ideas where am i going wrong please?
Controller
<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);
}
});
});
});