MVC Ajax Post Requirements
Does the ActionResult Method in the Controller require the attribute
[HttpPost] to successfully respond to an ajax post from JQuery?
$.ajax({
url: "~/../../User/AssignPermission",
type: "POST",
data: $.postify({ "p_permId": optionSelectedPerm.value, "p_UserId":
iUserId }),
cache: false,
success: function () {
alert("Success");
},
error: function () {
alert("FAIL");
}
});
Controller::
[HttpPost]
public ActionResult AssignPermission(int p_permId, int p_Userid)
{
blah blah blah dance with the provided Id's
persist new permission for user to Disk
return RedirectToAction("UserPermissions", "User", new {
uzrEditId = p_Userid });
}
I was successful getting back into the controller with a GET ( including
the data values as parameters) but this isnt allowing me to update the
View so I want to try a redirect but this will need a POST. Of course it
was a different ActionResult in the controller which danced with View
Model lists.. That should be pointless since UserPermissions", "User" does
that all in the beginning
function SwapPermission(optionSelectedPerm) {
$.ajax({
url: '~/../../User/AssignPermission',
data: $.postify({ "p_permId": optionSelectedPerm.value
}),
type: 'GET',
datatype: "json",
contentType: "application/json; charset=utf-8",
success: function () {
},
fail: function () {
alert("There was a problem saving the Permission
assignment");
}
});
}
No comments:
Post a Comment