I've been struggling to send 2 parameters from the View to the controller using an ajax call. Everything was working fine when I had only one parameter, but as soon as I added another, the function stopped working.
Below is the Javascript code with ajax:
function DeleteRole(roleId) {
var confirmation = confirm("Are you sure you want to delete this Role?");
if (confirmation) {
$.ajax({
type: "POST",
url: '@Url.Action("Delete_Role", "Admin")',
dataType: 'json',
data: JSON.stringify({
roleId: roleId,
applicationId: $('#AppList').val()
})
}).success(function (response) {
if (response.success) {
alert(response.responseText);
$(".k-grid").data("kendoGrid").dataSource.read();
} else {
alert(response.responseText);
}
}).error(function() {
alert("Error during Deletion");
});
}
}
Here is the MVC controller method (it seems like no information is reaching here):
[HttpPost]
public JsonResult Delete_Role(Guid rowId, Guid applicationId)
{
var users = new UserStore().ReadForAppRole(applicationId, rowId);
if (users.Any())
{
return Json(new { success = false, responseText = "There are currently Users within this Role" },
JsonRequestBehavior.AllowGet);
}
new RoleStore().RemoveRole(applicationId, rowId);
return Json(new { success = true, responseText = "Role successfully deleted" },
JsonRequestBehavior.AllowGet);
}