Hanusha Loujith

Hanusha Loujith

  • 1.8k
  • 292
  • 5.6k

Reading session array from an external javascript file

Aug 5 2022 10:00 AM


In my MVC application I have a function to read the column names and store it in a session array. Below is the code which I used.

 public void SetViewBag(int id)
                SqlCommand cmd = new SqlCommand("obps_sp_getColDetails", con);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlDataReader rdr = cmd.ExecuteReader();
                List<string> colname = new List<string>(250);

                while (rdr.Read())
                Session["colname"] = colname;


 This session values are accessed from a view page using the code which shown in the image attached.

Now I want to remove this from the view page and add this function in a seperate javascript file. 
But when I used the function Test same like this in the js file, it is throughing error. 
Can some please help me to find a way to read the session array inside a javascript file.

Answers (1)