Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 passing base class to partial View - submitting form only has parent class values
    primarykey
    data
    text
    <p>I have a number of child ViewModel classes which inherit from an base ViewModel class.</p> <p>I pass my child ViewModel into my View, which then passes itself into a partial view. The main view takes the child type, but the partial view takes the Parent type.</p> <p>Everything displays correctly when I manually populate the properties. However, when I Submit the form, my controller action only has properties for the Child class - none of the base class properties are completed?</p> <p>e.g.</p> <pre><code>public abstract class BaseDetails { public string Name { get; set; } public BaseDetails() { } public BaseDetails(string name) { Name = name; } } public class LocalDetails:BaseDetails { public int Visits { get; set; } public LocalDetails() { } public LocalDetails(int visits, string name) :base(name) { Visits = visits; } } </code></pre> <p>With the View as simple as:</p> <pre><code>@using (Html.BeginForm()) { @Html.TextBoxFor(m =&gt; m.Visits) &lt;br /&gt; @Html.Partial("Name", Model) &lt;input id="Submit1" type="submit" value="submit" /&gt; } </code></pre> <p><em>The partial view has a single textbox on it.</em></p> <p>In IE: ViewSource shows the form tag is around both tetxboxes.</p> <p>However, when I submit to the controller method:</p> <pre><code>[HttpPost] public ActionResult EditLocal (LocalDetails model) </code></pre> <p>model.Visits is correctly populated, but model.Name is null?</p> <p>Any ideas? I added parameterless constructors to the classes because I got an exception upon submission if I didn't.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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