title: How to pass Form Values to the Controller in .NET MVC
body: <p>In ASP.net MVC:</p>
  
  <p>How should/Can I pass Form data (From the View) to the Controller? </p>
  
  <p>This is the way I am heading :</p>
  
  <ul>
  <li>The Controller Index function is passing a ViewModel object to the View. </li>
  <li>The ViewModel object contains a paginated list as well as some SelectLists.
  _ The ViewModel object also contains a custom class I named theFilter. This class' purpose is to hold the Filter information Posted from the View via a Form.</li>
  <li>I want the  Index [AcceptVerbs(HttpVerbs.Post)] function to receive theFilter object populated with the form data, as well as the page number (as is it right now)</li>
  </ul>
  
  <p>Here are snippets of my code:</p>
  
  <p>The Controller/Index postback function:</p>
  
  <pre><code>    [AcceptVerbs(HttpVerbs.Post)]
      public ActionResult Index(int? page, CaseFilter caseFilter)
      {
          const int pageSize = 10;
          var cases = caseRepo.FindAllCases();
          var paginatedCases = new PaginatedList&lt;Case&gt;(cases, page ?? 0, pageSize);
          return View(new CaseIndexViewModel(paginatedCases, caseFilter));
      }
  </code></pre>
  
  <p>The Filter Class:</p>
  
  <pre><code>public class CaseFilter
  {
      int iVolume_id = 0,
          iSubject_id = 0;
  
      public CaseFilter() {
  
      }
  
      public int Volume_id { get { return iVolume_id; } set { iVolume_id = value; } }
      public int Subject_id { get { return iSubject_id; } set { iSubject_id = value; } }
  
  }
  </code></pre>
  
  <p>And the ViewModel class:</p>
  
  <pre><code>    public class CaseIndexViewModel
      {
      public PaginatedList&lt;Case&gt; PaginatedCases { get; private set; }
      public CaseFilter CaseFilter { get; private set; }
  
      public CaseIndexViewModel(PaginatedList&lt;Case&gt; paginatedCases, CaseFilter caseFilter)
      {
  
         PaginatedCases = paginatedCases;
         CaseFilter = caseFilter;
      }
  }
  </code></pre>
  
  <p>Basically I am trying to avoid using Request.Form to populate the Filter class, at least not to use it within the Controller.</p>
  
  <p>Any help, suggestions or disses are welcome!</p>