title: Where should i store my temporary view model in asp.net MVC?
body: <p>I have created a page where users can select an answer from random questions.</p>
  
  <p>The controller contains</p>
  
  <pre><code> public class TestController : Controller
          {
  
              private DBDataContext _context;
              private HomeViewModel _model;
  
              public TestController()
              {
                  _context = new DBDataContext();
                  _model = new HomeViewModel();
              }
  
              // GET: Test 
              [Route("test-online")]
              public ActionResult Index()
              {
                  _model = new HomeViewModel()
                  {
                      Categories = _context.Categories.Select(x =&gt; x.ToCategories()).ToList(),
                      QuestionModel = new List&lt;QuestionModel&gt;()
                  };
  
                  ViewData.Model = _model;
  
                  return View(_model);
              }
  
              [HttpPost]
              public void Go(Test t)
              {
                  _model = (HomeViewModel)ViewData.Model;
              }
  
              protected override void Dispose(bool disposing)
              {
                  if (disposing)
                  {
                      if (_context != null)
                      {
                          _context.Dispose();
                          _context = null;
                      }
                  }
                  base.Dispose(disposing);
              }
  }
  </code></pre>
  
  <p>And the problem is where should i store my <code>_model</code>?</p>
  
  <p>When a user selects an answer an ajax post is performed onto the <code>Go</code> method,
  but unfortunately the <code>ViewData.Model</code> is now <code>null</code></p>
  
  <p>How can i fix this issue?
  I tried both with <code>ViewBag</code> and <code>ViewData</code> since i do not want to use a public static property.</p>