Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you are trying to do will never work without custom ModelBinder (and even then it will be a huge mess I'd not recommend to implement), sorry. </p> <p>Only when you are passing a model from Controller to View it remembers what type it was originally (including inheritance, etc.) because at that point you are still on the server side of the page and you are merely passing an object. </p> <p>Once you enter a view and submit a form all that does it creates some POST request with body containing list of values based on input names. </p> <p>In your case if you have a form based on PS1 and used all the fields as inputs, you would get something like:</p> <pre><code>POST: stationId = some value name = some value reference = some value </code></pre> <p>(there is no mention of the original type, controller, method, etc.)</p> <p>Now, what MVC does is that it checks what argument you are using in the header of the method (in your case ProductionStep(PSBase ps)).</p> <p>Based on the argument it calls a model binder. What the default model binder does is that it creates new instance of that class (in your case PSBase) and goes via reflection through all the properties of that class and tries to get them from the POST body.</p> <p>If there are some extra values in the POST body those are forgotten.</p> <p>Unless you write a custom model binder for this default MVC implementation can't help you there. </p> <p>I'd recommend creating two separate methods, one of each accepting different implementation of PSBase.</p> <p>If you want to read more on Model Binders check this out <a href="http://msdn.microsoft.com/en-us/magazine/hh781022.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/magazine/hh781022.aspx</a></p> <p>EDIT:</p> <p>By creating two separate methods I mean something like this:</p> <pre><code>[HttpPost] public ActionResult ProductionStepA(PS1 ps) { if (ModelState.IsValid) { } return View(); } [HttpPost] public ActionResult ProductionStepB(PS2 ps) { if (ModelState.IsValid) { } return View(); } </code></pre> <p>then you have to distinguish between them in the view via different form action.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload