Share via

can't use hidden field to pass role and file no from action result index resignation to Pending Managers action ?

Ahmed Salah Abed Elaziz 390 Reputation points
2024-01-09T21:35:52.3066667+00:00

I work on asp.net mvc . i face issue when pass user role and User code

from IndexResignation action to PendingManagersRequests action using

session because it share values between browsers .

so How to use another way instead of session as hidden field .

public ActionResult IndexResignation(string filenumber)
 {
     int employeeFileNo;
     string userRole;



     if (!string.IsNullOrEmpty(filenumber))
     {

         if (int.TryParse(filenumber, out employeeFileNo))
         {
             JDEUtility jde = new JDEUtility();
             userRole = Workforce.ResignationGetUserRole(employeeFileNo);


                 Session[SessionKeys.UserCode] = employeeFileNo;
             if (!string.IsNullOrEmpty(userRole))
             {

                 Session[SessionKeys.RoleCode] = userRole;
             }

             if (userRole == RoleKey.LM || userRole == RoleKey.DM || userRole == RoleKey.LDM)
             {

                 return RedirectToAction("PendingManagersRequests", "Resignation", null);
             }



         }
         else
         {
             ViewBag.errorMsg = "incorrect file no";
         }
     }
     else
     {
         ViewBag.errorMsg = "unauthorized user";
     }

     return View();
 }

     public async Task<ActionResult> PendingManagersRequests(string msg, string errorMsg)
     {
        // how to pass user role and user code to action PendingManager
     }
ASP.NET (C#)
 

can you show me view and action what will be if i use hidden fields ?

Index resignation action not have view

PendingMangerRequest action have view

so can you show me please how to use hidden field by code on level of action result and view with code when pass data

Developer technologies | ASP.NET | Other
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 31,176 Reputation points
    2024-01-09T23:29:09.03+00:00

    If I understand correctly, you are asking how to pass data from the IndexResignation action to the PendingManagersRequests() action without using Session. Use the RedirectToAction() method and add the parameters you wish to pass. You'll need update the PendingManagersRequests to include the two new parameters.

     public async Task<ActionResult> PendingManagersRequests(string msg, string errorMsg, string userRole, string userCode)
     {
        // how to pass user role and user code to action PendingManager
     }
    
    
    

    The RedirectToAction() syntax.

    return RedirectToAction("PendingManagersRequests", "Resignation", 
        new { 
            msg = "", 
            errorMsg = "", 
            userRole = userRole, 
            userCode = employeeFileNo
        });
    

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.