c# - Pass array to a view using query string MVC -


i have multiple roles , need pass roles view via return redirectto action method,

my code

string[] roles = new string[] { "admin", "supervisor", "interviewer" }; if (roles.count() > 1) {     return redirecttoaction("loginas","admin",new{@roles = roles}); } 

when pass in loginas view shows me url this,

http://localhost:33883/admin/loginas?roles=system.string[] 

but there's no passed values.

option 1 :

    public actionresult index()     {         string[] roles = new string[] { "admin", "supervisor", "interviewer" };         var routeparameters = new routevaluedictionary();         (int = 0; < roles.length; i++)         {             routeparameters["roles[" + + "]"] = roles[i];         }         return redirecttoaction("test", "student", routeparameters);     }      public actionresult test(string[] roles)     {         return view("index");     } 

output -

enter image description here

option 2: use tempdata

    public actionresult index()     {         string[] roles = new string[] { "admin", "supervisor", "interviewer" };         tempdata["data"] = roles;         return redirecttoaction("test", "student");     }      public actionresult test()     {         string[] roles = (string[])tempdata["data"];         return view("index");     } 

output -

enter image description here

option 3 : use session

    public actionresult index()     {         string[] roles = new string[] { "admin", "supervisor", "interviewer" };         session["data"] = roles;         return redirecttoaction("test", "student");     }      public actionresult test()     {         string[] roles = (string[])session["data"];         return view("index");     } 

output -

enter image description here


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -