title: Reusing ActionResult code within Controller
body: <p>If I have the following code <strong>(EDIT: Sorry if I wasn't clear, I want to encapsulate the following (forget about the view its calling), so that I could do other stuff within the <code>ActionResult</code>)</strong>:</p>
  
  <pre><code>public ActionResult ModelBased(string[] items, PostedItems postedItems) {
          var model = new ItemsViewModel();
          var selectedItems = new List&lt;Item&gt;();
          var postedItemIDs = new string[0];
          if (postedItems == null) postedItems = new PostedItems();
  
          if (items!= null &amp;&amp; items.Any()) {
              postedCityIDs = items;
              postedItems.ItemIDs = items;
          }
  
          if (postedItems.ItemIDs != null &amp;&amp; postedItems.ItemIDs.Any()) {
              postedItemIDs = postedIems.ItemIDs;
              model.WasPosted = true;
          }
  
          if (postedItemIDs.Any())
              selectedItems = ItemRepository.GetAll()
                  .Where(x =&gt; postedItemIDs.Any(s =&gt; x.Id.ToString().Equals(s))).ToList();
  
          model.AvailableItems = ItemRepository.GetAll();
          model.SelectedItems = selectedItems;
          model.PostedItems = postedItems;
  
          return View(model);
      }
  </code></pre>
  
  <p>How might I reuse it in different Actions in my controller without having to copy/paste. I tried doing a private method with the code. But I am stuck on:</p>
  
  <ol>
  <li><p>Either calling it wrong within an action method : <code>private void Item (Item item) {//copied code from above}</code> then calling <code>Item(item);</code> in the action; or </p></li>
  <li><p>It has something to do with the <code>(string[] items, PostedItems postedItems)</code> that I am doing wrong; or</p></li>
  <li><p>Something entirely different that I am not doing right.</p></li>
  </ol>
  
  <p>Any examples would be much appreciated.</p>
  
  <p><strong>EDIT:</strong> The code above works with a CheckBoxList. It's one particular CheckBoxList. But I want to be able to use it in other views without having to copy/paste the code to other <code>ActionResults</code>. Just calling the <code>ActionResult</code> won't work, because I plan on doing other things. In particular, I have code for wizards in each <code>ActionResult</code>, such as:</p>
  
  <pre><code>if ((nextButton != null) &amp;&amp; ModelState.IsValid)
       return RedirectToAction("EMailConfirm");
  return View("EMail/BasicDetails", myData);
  </code></pre>
  
  <p>which are returning specific views, so call to just the <code>ActionResult</code> won't work, unless I am missing something.</p>