Note that there are some explanatory texts on larger screens.

plurals
  1. PONull Values returned to Controller for Edit action
    text
    copied!<p>I have the following actions in my controller. The first (top) <code>Edit</code> works fine and serves the correct values. However, in the second one, i.e. the 'return' <code>Edit</code>, every property of model is at default value, i.e. null for ref types and zero for value types. I have examined the HTTP post data and it has all the properties correctly named and with correct values. What could be wrong?</p> <p><strong>Controller excerpt:</strong></p> <pre><code> [Authorize(Order = 0, Roles = "Requester, Controller")] public ActionResult Edit(int id) { JobCardViewData viewData = ViewDataFactory.CreateBaseViewData&lt;JobCardViewData&gt;("Installation Details"); viewData.JobCard = new JobCardService().GetById(id); return View(viewData); } [HttpPost] public ActionResult Edit(JobCard model) { try { new JobCardService().Update(model); var x = RedirectToAction("Index"); return RedirectToAction("Index"); } catch (Exception) { return RedirectToAction("Edit", new {id = model.InstallationNumber}); } } </code></pre> <p><strong>View excerpt:</strong></p> <pre><code> &lt;div class="editor-label"&gt; &lt;%: Html.LabelFor(model =&gt; model.JobCard.Name) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%: Html.TextBoxFor(model =&gt; model.JobCard.Name) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.JobCard.Name) %&gt; &lt;/div&gt; &lt;div class="editor-label"&gt; &lt;%: Html.LabelFor(model =&gt; model.JobCard.Surname) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%: Html.TextBoxFor(model =&gt; model.JobCard.Surname) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.JobCard.Surname) %&gt; &lt;/div&gt; </code></pre>
 

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