Click here to Skip to main content
15,887,251 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I work on ASP.NET MVC Project. I face issue action ApprovalIndex Not redirect to action PendingManagersRequests although no error happens.

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

So why is it not redirecting to view PendingManagersRequests although no issues happen.

What I have tried:

1. When click button approves submit, it updates table column SpeakStuffComment based on Request No:
JavaScript
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;">class="glyphicon glyphicon-ok"> 
         Approve </a>
        }

2- When click approve button, it calls ApprovalIndex on controller ResignationController:
JavaScript
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:
JavaScript
    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);
                }
            });
        }
    }
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);
    }
Posted
Updated 24-Oct-23 12:33pm
v2
Comments
Dave Kreskowiak 18-Oct-23 10:13am    
At the risk of wasting my time, do you have a view in the Views\Resignation folder called PendingManagersRequests, you better make sure the spelling is correct?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900