model-view-controllermvccontribmvccontrib-grid

How do I Pass a Variable from one Controller to another using MVC Contrib?


Jeremy Skinner has a blog and a video about exporting a spreadsheet from MVC Contrib. The problem is there is no filtering done in his video or blog. In the controller associated with page containing the grid, I have the filters and in the controller associated with the "Export to Spreadsheet, I need that filter without being reset. The problem is, the variable gets reset everytime I click on the "Export to Spreadsheet" link. How do I get that variable from one controller to another without resetting?

Here is Jeremy's link, http://www.jeremyskinner.co.uk/2010/04/28/mvccontrib-grid-presentation. Thank you!!


Solution

  • I ended up creating a Session variable like this:

    1- Enable the session variable by editing the web.config with this:.

    <configuration>
       <system.web>
          <sessionState cookieless="true" regenerateExpiredSessionId="true" />
       </system.web>
    </configuration>
    

    2- Create Session State in first controller

    Session["FirstName"] = FirstNameTextBox.Text;
    

    3- Use Session State in second contoller

    string firstName = (string)(Session["FirstName"]);