I have a code snippet in which my controller function is not being triggered for users who do not have the role of "Admin". Can someone help me identify where I went wrong? Just to clarify, the controller function works fine for users with the role of "Admin", but it does not get called for any other roles.
VIEW:
function acceptTerms() {
var userName = '@Html.ValueFor(m => m.UserName)';
$.ajax({
type: "POST",
url: '@Url.Action("UpdateUserConnects", "User")',
data: JSON.stringify({ userName: userName }),
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data == "Failed") {
alert("failed");
}
else {
var wnd = $("#wndTerms").data("kendoWindow");
wnd.close();
$.ajax({
type: "POST",
url: '@Url.Action("AcceptTerms", "Account")',
contentType: "application/json; charset=utf-8",
success: function (data) {
window.location.href = data
}
});
}
}
});
}
CONTROLLER:
[AcceptVerbs(HttpVerbs.Post)]
public String UpdateUserConnects(string userName)
{
try
{
UsersService usersService = new UsersService();
Users user = usersService.GetUserByUsername(userName);
if (user != null) {
user.previouslyConnected = true;
usersService.UpdateUser(user);
}
}
catch (Exception e) {
return "Failed";
}
return "Success";
}