Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6238693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:15:36+00:00 2026-05-24T11:15:36+00:00

So, I have this variable that I push into the controller via POST from

  • 0

So, I have this variable that I push into the controller via POST from a form in my view.

I then push the variable into viewdata so it’s available to the next view which is fine. But that view has no need of a form so I’m unable to push that same variable into the next controller. In short, it’s cumbersome to push pieces of information back and forth from controller to view and reverse, so I’m looking for a way to keep a global variable alive inside a controller so that it’s accessible by all action results… The general breakdown of my program is this…

-User types a "name"

-I send "name" to controller.
-I push 'name' into viewstate (query entity framework to get a list of stuff 'name'
   has access to) and return that list into the view.
-In that view I can access the 'name' since it was in view state.
-Clicking on a link inside the page takes me to another controller where I need 
   to get access to 'name' WITHOUT passing view Routing or POST.

Obviously the easiest way would be to declare ‘name’ globally and then it’s always available but for the life of me I can’t figure out how.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:15:36+00:00Added an answer on May 24, 2026 at 11:15 am

    Have you considered storing it in the Session?

    This will allow you to easily access it, either from your controller or views, and avoids the need for global variables.

    Storing:

    [HttpPost] 
    public ActionResult YourPostMethod(string name)
    {
        Session["Name"] = "yourName";
    }
    

    Access: *

    Make Sure to check that it exists prior to grabbing it:

    var whatsMyName = (Session["Name"] != null) ? Session["Name"] : "";
    

    Scalability Consideration

    It’s worth mentioning that MVC applications are designed to mimic the web and are stateless. Introducing Session variables changes this, so be aware that it can introduce issues regarding scalability, etc.

    Each user that stores data within the Session will take up resources at the server level. Depending on the number of users and what you are storing within the Session, you could potentially run out of memory if those values become too large.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable that contains a 4 byte, network-order IPv4 address (this was
I have a file that contains this kind of paths: C:\bad\foo.c C:\good\foo.c C:\good\bar\foo.c C:\good\bar\[variable
I have an server (available via ssh) on the internet that my friend and
I have a list of variable names, like this: ['foo', 'bar', 'baz'] (I originally
I have a variable of type Hashmap <String,Integer >. In this, the Integer value
I have this code in jQuery, that I want to reimplement with the prototype
Before iOS4, my app's initial view controller would check a passcode on/off settings variable
I'll try to explain this as best as I can. I have a form
I have this map<string, vector <pair<int, int> > > variable and I'm pushing back
I have 3 variables like this: $first = 2; $second = 5; $operation =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.