Question issue approval index action not redirect to pending action view although no error on debug code?

ahmedaziz

Well-known member
Joined
Feb 22, 2023
Messages
55
Programming Experience
1-3
I work on asp.net mvc Project .I face issue action ApprovalIndex Not redirect to action PendingManagersRequests although no error happen .

I debug and trace breakpoint until reach action PendingManagersRequests and trace until I reach to view return View(vmr); without any issues .

so why it not redirect to view PendingManagersRequests Although no issues happen

steps to my code

1- when click button approve submit it update table column SpeakStuffComment based on Request No

C#:
 using (Html.BeginForm("ApprovalIndex", "Resignation", new { id = Model.RequestNo }, FormMethod.Post, htmlAttributes: new { @style = "display:inline;" }))
        {
            @Html.AntiForgeryToken()
        
                                    < a onclick="submit();" class="btn btn-primary" style="min-width: 100px;
            margin-left: 5px;"><i class="glyphicon glyphicon-ok"></i> Approve </a>
        }

2- when click approve button it call ApprovalIndex on controller ResignationController
approval indx action call:
public class ResignationController : Controller
    {
[HttpPost]
        public async Task<ActionResult> ApprovalIndex(ResignationRequester REQ)
        {
            string errorMsg = string.Empty;
            string requestStatus;
          

                 Workforce.ResignationUpdateLineManangerApproval(id, true,Convert.ToInt32(Session[SessionKeys.UserCode]));
                    return RedirectToAction("PendingManagersRequests", new { msg = $"Request NO {REQ.RequestNo} has been accepted " +
                        $"successfully." });
          
        }
   }

3-jquery call action approvalIndex on resignation controller

C#:
 function submit() {
        var ResignationRequester = new Object();
        ResignationRequester.RequestNo = document.getElementById("RequestNo").innerHTML.trim();
        ResignationRequester.EmpID = document.getElementById("EmpID").innerHTML.trim();
        ResignationRequester.SpeakStuffComment = document.getElementById("SpeakStuffComment").value;


        if (ResignationRequester != null) {
            $.ajax({
                type: "POST",
                url: '@Url.Action("ApprovalIndex", "Resignation")',
                data: JSON.stringify(ResignationRequester),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    console.log(response);
                },
                failure: function (response) {
                    alert(response.responseText);
                },
                error: function (response) {
                    alert(response.responseText);
                }
            });
        }
    }
C#:
public async Task<ActionResult> PendingManagersRequests(string msg, string errorMsg)
    {
      
        ViewModelRequests vmr = new ViewModelRequests();
      
        vmr.MyRequests = Workforce.GetPendingToDisplayMyRequests(Session[SessionKeys.UserCode].ToString());

                
        ViewBag.msg = msg;
        ViewBag.errorMsg = errorMsg;
        return View(vmr);
    }

finally I get only this popup localhost say although from action approvalindex no error

error localhost.png
 
To me, the fact that you got some popup suggests that the failure or error clauses of your AJAX call was the response recieved by the browser.

I don't know whether you are allowed to do a redirect as part of an AJAX response. What happens if you just return a dummy success response from the Index HTTP POST instead of attempting to redirect?
 

Latest posts

Back
Top Bottom