Note that there are some explanatory texts on larger screens.

plurals
  1. POLosing data on post when using EditorFor
    primarykey
    data
    text
    <p>The Problem:</p> <p>When I submit the form I am losing any information entered into the edit templates for the addresses.</p> <p>I have the following model:</p> <pre><code>public class MoveRecord { public Address StartPoint { get; set; } public Address EndPoint { get; set; } } </code></pre> <p>Where Address is defined as:</p> <pre><code>public class Address { public String City { get; set;} public String State { get; set; } public String Line1{ get; set; } public String PostalCode { get; set; } } </code></pre> <p>Here is my action method:</p> <pre><code>[HttpPost] public ActionResult Edit(MoveRecord model) { if (ModelState.IsValid) { //Save info } return View(model); } </code></pre> <p>My edit view uses:</p> <pre><code>using (Html.BeginForm("Edit", "Move", FormMethod.Post)) { @Html.EditorFor(m =&gt; m.StartPoint); @Html.EditorFor(m =&gt; m.EndPoint); &lt;input type="submit" value="Save" /&gt; } </code></pre> <p>My edit template is:</p> <pre><code>&lt;table class="form address"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;th style="width: 200px;"&gt; @Html.LabelFor(m =&gt; m.Line1): &lt;/th&gt; &lt;td&gt; @Html.TextBoxFor(m =&gt; m.Line1, new { style = "width: 300px;" }) &lt;/td&gt; &lt;/tr&gt; &lt;tr id="zip"&gt; &lt;th&gt; @Html.LabelFor(m =&gt; m.PostalCode): &lt;/th&gt; &lt;td&gt; @Html.TextBoxFor(m =&gt; m.PostalCode, new { style = "width: 150px;" }) &lt;/td&gt; &lt;/tr&gt; &lt;tr id="city"&gt; &lt;th&gt; @Html.LabelFor(m =&gt; m.City): &lt;/th&gt; &lt;td&gt; @Html.TextBoxFor(m =&gt; m.City, new { style = "width: 150px;" }) &lt;/td&gt; &lt;/tr&gt; &lt;tr id="state"&gt; &lt;th&gt; @Html.LabelFor(m =&gt; m.StateProvince): &lt;/th&gt; &lt;td&gt; @Html.TextBoxFor(m =&gt; m.StateProvince, new { style = "width: 150px;" }) &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>Everything renders just fine, however when I submit the form the model that I get in the action method does not contain any information entered into the address field. If I move everything into the same view then it works just fine but what I would like is to be able to use the editor templates to keep my views easy to read. <strong>How can I get the data from the editor template correctly bound to the model?</strong></p> <p>Edit: Posted my action method</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