Display Message Box after Delete data using jQuery AJAX in ASP.Net MVC

Last Reply on Apr 04, 2019 02:05 AM By dharmendr

Posted on Apr 03, 2019 11:58 PM

Hello all,

I have a submit button currently being used to assign roles.

I have a second button to remove the roles. To remove the roles I call an $.ajax call and I pass my controller with the id to my action.

This works BUT my TempData[msg] isn't being stored so when the call finishes no message is displayed like when I add a role.

Also the Roles are not being refreshed with my 'return RedirectToAction()' at the end of my action method.

Here is what I have is there a way I can get those small things working or what are some more ideas to do this?

Thank you

            //VIEW This is where I am getting my userId from this DropDownList 
            <div class="row">
                <div class="col-md-4">
                    @Html.DropDownListFor(a => a.UserId,
                     new SelectList(Model.lstAdmins, "UserId", "Name"),
                     new { @class = "form-control", @id = "userAdmins" })
                    @* , @onChange = "SelectedValue(this)"*@
                    @Html.HiddenFor(a => a.UserId)
                    @Html.ValidationMessageFor(a => a.UserId)
                <div class="col-md-4"></div>
                <div class="col-md-4"></div>
            </div><div class="row">
                @for(var i = 0; i < Model.lstUsers.Count(); i++)
                    <div class="col-md-4">
                            @Html.CheckBoxFor(u => Model.lstUsers[i].SelectedUsers)
                                @Html.DisplayFor(u => Model.lstUsers[i].Name)
                                @Html.HiddenFor(u => Model.lstUsers[i].UserId)
                                @Html.HiddenFor(u => Model.lstUsers[i].Name)
            <br />
            <div class="row">
                <div class="form-group">
                    <div class="col-md-offset-0 col-md-12">
                        <input type="submit" value="Assign Role" class="btn btn-success" />
                        @* @Url.Action("RemoveAdmin", "SuperAdmin") *@

                        <button type="button" onclick="clickMe()"
                                class="btn btn-danger">
                            Remove Role

                        @Html.ActionLink("Cancel", "Dashboard", "SuperAdmin",
                         null, new { @class = "btn btn-danger" })


    function clickMe() {
        var userid = $("#userAdmins").val();
        if (userid != "") {
                url: "RemoveAdmin/SuperAdmin",
                data: { userid: userid },
                type: "POST",
                //success: function () {
                //    alert("Success");


        public ActionResult RemoveAdmin(string userid)
            ApplicationUser au = context.Users.Where(u => u.Id.Equals(userid,
            var store = new UserStore<ApplicationUser>(context);
            var manager = new UserManager<ApplicationUser>(store);
            manager.RemoveFromRole(au.Id, "Admin");
            manager.AddToRole(au.Id, "User");

            TempData["Success"] = "Roles Assigned Successfully";
            return RedirectToAction("AssignAdmin");


This question does not have replies that have been liked.