title: MVC3 button click to populate html table and removed personal passage
body: <p>I am new to MVC3 and trying to work on my first small project at work. I have a HomeController with two actions, Index() and GetData(). Index just returns the Index view. When the Index page loads, I want there to be an html Button or Input of type Button. When I click on this button, I want the GetData action to run, which selects some data based on a linq query and returns a List. Then in the Index view itself, below the button which i clicked, I want the list to be populated onto an html table .....I assume using a foreach loop.</p>
  
  <p>This is not working, and I think I am clearly misunderstanding the concept of this MVC pattern.</p>
  
  <p>My Controller Code:</p>
  
  <pre><code>    private ReferenceDataContext data = new ReferenceDataContext();
  
      public ActionResult Index()
      {
  
          return View();
  
      }
  
      public ActionResult GetData()
      {
  
          using (data)
          {                
              var hosp = (from x in data.Hospitals
                            where x.HAcode == "Q36"
                            select x).ToList();
              ViewData["hosp"] = hosp;
              return RedirectToAction("Index");                
          }
  
      } 
  </code></pre>
  
  <p>My View Code:</p>
  
  <pre><code>@model IEnumerable&lt;NursingHomes.Models.Hospitals&gt;
  
  @{
      ViewBag.Title = "Hospitals Verify";
  }
  
  
  &lt;br /&gt;
  &lt;br /&gt;
  @using (Html.BeginForm("GetData", "Home")) 
  { 
  &lt;input type="submit" value="Submit" title="Get Data" /&gt;  
  
  &lt;h2&gt;Nursing Homes&lt;/h2&gt;
  
  &lt;table&gt;
  &lt;tr&gt;
  &lt;th&gt;Code&lt;/th&gt;
  &lt;th&gt;HAcode&lt;/th&gt;
  &lt;th&gt;Name&lt;/th&gt;
  
  &lt;/tr&gt;
  
  @foreach (NursingHomes.Models.Hospitals item in (List&lt;NursingHomes.Models.Hospitals&gt;)    ViewData["hosp"])
  { 
  &lt;tr&gt;
  &lt;td&gt;
  @Html.DisplayFor(modelItem=&gt;item.Code)
  &lt;/td&gt;
  &lt;td&gt;
  @Html.DisplayFor(modelItem=&gt;item.HAcode)
  &lt;/td&gt;
  &lt;td&gt;
  @Html.DisplayFor(modelItem=&gt;item.Name)
  &lt;/td&gt;
  
  &lt;/tr&gt;
  
  }
  
  &lt;/table&gt;
  
  } 
  </code></pre>
  
  <p>I am doing something wrong above? Is is this simply not possible without the use of JQuery?</p>
  
  <p>Basic question is, how can click on that button on the Index page, and tell it to run the GetData action and then build the table below the button using the returned List from the GetData action.</p>