title: Conditional RedirectToAction in Controller?
body: <p>I'm just wondering where, in MVC, the responsibility for determining where to redirect belongs. I <em>think</em> it's the controller, but I'm not sure.</p>
  
  <p>In the Create action of a <code>WorkshopItem</code> I'm creating a new WorkshopItem from the ViewModel passed in, then saving it to the database. Part of the ViewModel is a <code>SelectedCustomerId</code> and <code>CustomerName</code>, if the SelectedCustomerId is empty and the name is empty I get the <code>default customer</code> entity and associate it with the item. If the Id is empty but the name is not then the user has searched for a customer but no matches were found, so I take the value and create a new customer record and attach it. </p>
  
  <pre><code>[NHibernateActionFilter]
  [HttpPost]
  public ActionResult Create(WorkshopItemCreateViewModel model)
  {
      try
      {
          Customer customer = null;
  
          if (model.SelectedCustomerId == new Guid() &amp;&amp; 
                 !string.IsNullOrWhiteSpace(model.CustomerName))
              customer = CreateNewCustomer(model.CustomerName);
          else if (model.SelectedCustomerId == new Guid() &amp;&amp;
                  string.IsNullOrWhiteSpace(model.CustomerName))
          {
              // Assign the System Valued customer if no customer was selected.
              var id = Guid.Parse(ConfigurationManager.AppSettings["ValuedCustomerId"]);
              customer = Session.QueryOver&lt;Customer&gt;()
                                .Where(c =&gt; c.Id == id)
                                .SingleOrDefault();
          }
  
          // other stuff
          return RedirectToAction("Index");
  </code></pre>
  
  <p>This is working fine, but now I want to also <code>RedirectToAction</code> depending on whether a customer record was created or not because if a customer was created it only has a <code>Name</code> and I'd like to redirect to the Edit action on the Customer Controller passing the CustomerId (which I think I can do). My question is really whether this is valid to do in MVC or should this be a responsibility elsewhere?</p>
  
  <p>This would look like this:</p>
  
  <pre><code>[NHibernateActionFilter]
  [HttpPost]
  public ActionResult Create(WorkshopItemCreateViewModel model)
  {
      try
      {
          Customer customer = null;
          bool newCustomer = false;
          if (model.SelectedCustomerId == new Guid() &amp;&amp; 
                 !string.IsNullOrWhiteSpace(model.CustomerName))
          {
              customer = CreateNewCustomer(model.CustomerName);
              newCustomer = true;
          }
          else if (model.SelectedCustomerId == new Guid() &amp;&amp;
                  string.IsNullOrWhiteSpace(model.CustomerName))
          {
              // Assign the System Valued customer if no customer was selected.
              var id = Guid.Parse(ConfigurationManager.AppSettings["ValuedCustomerId"]);
              customer = Session.QueryOver&lt;Customer&gt;()
                                .Where(c =&gt; c.Id == id)
                                .SingleOrDefault();
          }
  
          // other stuff
          if (newCustomer)
              return RedirectToAction("Edit", "Customer", new {id=customer.Id});
          else
              return RedirectToAction("Index");
  </code></pre>