title: ActionResult cast parameter base class to derived class
body: <p>I've written a base class and some classes which derive from it. </p>
  
  <p>I want to use these classes in one ActionResult, but if I'm trying to cast PSBase to PS1 I'm getting a System.InvalidCastException that type PSBase can not be converted to PS1.</p>
  
  <p>Classes:</p>
  
  <pre><code>public class PSBase
  {
        public int stationId { get; set; }
        public string name { get; set; }
  }
  
  public class PS1 : PSBase
  {
        public string reference { get; set; }
  }
  
  public class PS2 : PSBase
  {
  }
  </code></pre>
  
  <p>ActionResult:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult ProductionStep(PSBase ps)
      {
          if (ModelState.IsValid)
          {
              var product = db.Product.FirstOrDefault(.........);
  
              switch (ps.stationId )
              {
                  case 1:
                      {
                          product.Reference = ((PS1)ps).reference;
                          db.SaveChanges();
                          break;
                      }
              }
          }
          return View();
      }
  </code></pre>
  
  <p>As I don't want to have for each class a own ActionResult (repeating much of the same code many times) I wanted put all this to one ActionResult. Any Ideas how I could implement this?</p>