Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC, passing values back from multiple partial views in a page
    primarykey
    data
    text
    <p>I have problem when I am trying to pass values back from my page which contains the same partial view twice. My class definiton is like below: </p> <pre><code>public class Account : IEntity { public decimal CurrentBalance { get; set; } public List&lt;Person&gt; AccountHolders { get; set; } //to get round the non-existing enum support in EF4.3 wrap enum to int public int StatusValue { get; set; } public AccountStatus Status { get { return (AccountStatus)StatusValue; } set { StatusValue = (int) value; } } public DateTime AccountOpenDate { get; set; } public DateTime AccountCloseDate { get; set; } public DateTime AccountSuspensionDate { get; set; } } </code></pre> <p>It has a List of Person , which I made a partial view for (for a single one).</p> <pre><code>&lt;fieldset&gt; &lt;legend&gt;Person&lt;/legend&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Name) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Name) @Html.ValidationMessageFor(model =&gt; model.Name) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Age) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Age) @Html.ValidationMessageFor(model =&gt; model.Age) &lt;/div&gt; &lt;/fieldset&gt; </code></pre> <p>In the Create page for the Account I include 2 of the partial views I created as below.</p> <pre><code> &lt;div id="Person1"&gt; @Html.Partial("_CreateAccountHolder" ) &lt;/div&gt; &lt;div id="Person2"&gt; @Html.Partial("_CreateAccountHolder") &lt;/div&gt; </code></pre> <p>When I look at what is posted back, it contains the values (Name and Age as the properties of Person) I put in the form values of the page and I have have the tow of them as expected: CurrentBalance=19&amp;Status=Closed&amp;AccountOpenDate=12%2F12%2F2012&amp;Name=mustafa&amp;Age=20&amp;Name=sofia&amp;Age=20&amp;AccountCloseDate=12%2F12%2F2012&amp;AccountSuspensionDate=12%2F12%2F2012</p> <p>But when I look at my create method on my controller I see the AccountHolder list as null. I tried with various signatures... public ActionResult Create(Account personalaccount, Person [] accountHolders) public ActionResult Create(Account personalaccount, List accountHolders)</p> <p>If I only have one partial view of Person and have my controller like this, I can see the Person object bound correctly. public ActionResult Create(Account personalaccount, Person accountHolder)</p> <p>Any ideas as to where I am going wrong?</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.
 

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