Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC4 - form doesn't show new model values
    text
    copied!<p>I have a controller with 2 actions: 1 for displaying a form and 2nd for processing the submitted form. Smth like this:</p> <pre><code>public ActionResult Create() { TestModel model = new TestModel() { Value1 = "aaa" }; return View(model); } [HttpPost] public ActionResult Create(TestModel model) { model.Value2 = "bbb"; return View(model); } </code></pre> <p>As you can see I pre-populate Value1 with "aaa" so it appears on the form - this part works fine. However, when I submit the form I would like to fill other properties of the model object and re-display the form using the same view.</p> <p>The problem is that on submit the form still displays the original model object and not the updated one i.e. only Value1 is populated with "aaa" and Value2 is empty.</p> <p>The view I use is the Auto-generated one by scaffolding option:</p> <pre><code>@using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;TestModel&lt;/legend&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Value1) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Value1) @Html.ValidationMessageFor(model =&gt; model.Value1) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Value2) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Value2) @Html.ValidationMessageFor(model =&gt; model.Value2) &lt;/div&gt; &lt;p&gt; &lt;input type="submit" value="Save" /&gt; &lt;/p&gt; &lt;/fieldset&gt; </code></pre> <p>}</p>
 

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