title: Implement back button in ASP.NET MVC
body: <p>I am facing issue implementing a back button feature in a ASP.NET MVC application.
  <br/>This is my Home page View, for simplicity let us consider it has a div which has img element and div that renders PartialView2. PartialView2 is a partial view which generates list of tiles based on the data from the <code>Model</code>. </p>
  
  <pre><code>View1:
  &lt;div&gt; remainig page content &lt;/div&gt;
      &lt;div&gt;
      &lt;img src="/path/to/img_back" id="img" /&gt;
      &lt;div id="1"&gt;
      Html.RenderAction("PartialView2", "Home");
      &lt;/div&gt;
      &lt;/div&gt;
  &lt;div&gt; remainig page content &lt;/div&gt; 
  
  
  PartialView2:
  @model ICollection&lt;Model&gt;
  @{
  foreach(item in Model) {
  &lt;div class="tile"&gt;
  &lt;!-- tiles data generated using model data that I get from controller --&gt; 
  &lt;/div&gt;
  }
  }
  </code></pre>
  
  <p>HomeController:</p>
  
  <pre><code>//field
  private Stack&lt;ICollection&lt;Model&gt;&gt; myStack = new Stack&lt;ICollection&lt;Model&gt;&gt;();
  
  public PartialViewResult GetTiles(string id) {
   var nodes = new List&lt;Model&gt;();
   //make a call to database and generating the list of child nodes of type Model.
   // get the rows from the db which have parentid as the passed value.
   //for back button: myStack.push(nodes);
  return PartialView("PartialView2",nodes);
  }
  
  //Method to call from jQuery on click of #img
  public PartialViewResult BackButton() {
  return PartialView("PartialView2",myStack.Pop());
  }
  </code></pre>
  
  <p>When I click on a tile, I make a call to GetTiles method in the home controller through Jquery Ajax and populate the <code>$("#1").html()</code> with the result returned from the ajax call which is the same partial view.</p>
  
  <p>When I click on <code>#img</code> I call <code>BackButton()</code> method from jQuery ajax to to load html of <code>#1</code> div in the page.</p>
  
  <p>Model:</p>
  
  <pre><code>string icon;
  string title;
  string parentid;
  string id;
  bool hasChildren;
  </code></pre>
  
  <p>With this design I only have the options to traverse the children and represent them as tiles but I need to implement a back button so as to traverse the parents. I have created a stack in the home controller and pushed the elements to the stack for each call to the <code>GetTiles()</code> method. But for every call to the controller, a new stack is instantiated. So my idea to have collection of models in the stack and on each call to back button pop the collection of <code>Model</code> and return it to the view is not working.</p>
  
  <p>Can you guys please help me solve this issue? Any in-memory data structures to use to hold the parent models?
  Please let me know if I need to provide further information.</p>