Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>@Html.ActionLink</code> produces an a tag which can only be used to call GET. Change to a submit button to get a POST.</p> <p>Normally with an Edit, you are only editing a sinble model rather than a collection on a page but going with what you have, change the cshtml to:</p> <pre><code>@model ICollection&lt;Organization&gt; &lt;table&gt; @foreach (var item in Model) { using (Html.BeginForm()) { var test = item.PartyId; &lt;tr id="@test"&gt; &lt;td class="txt"&gt; &lt;input type="text" name="Caption" class="txt" value="@item.Caption"/&gt; &lt;/td&gt; &lt;td class="txt"&gt; &lt;input type="text" name="NameInUse" class="txt" value="@item.NameInUse"/&gt; &lt;/td&gt; &lt;td class="txt"&gt; &lt;input type="text" name="Description" class="txt" value="@item.Description" /&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="hidden" name="PartyId" value="@item.PartyId"/&gt; &lt;button type="submit"&gt;Edit&lt;/button&gt; &lt;/td&gt; &lt;/tr&gt; } } &lt;/table&gt; </code></pre> <p>Now each table row is wrapped by a form meaning the submit button will post that data. The <code>name</code> attribute on the inputs will cause the MVC model binders to bind your posted values to your model correctly.</p> <p>This hidden input at the end will ensure your PartyId value gets posted back. The fact that it is in int (and not nullable) was giving the exception with your initial code I think.</p> <p>HTH</p> <p><strong>EDIT</strong></p> <p>Adding controller code (note - I still think this is a little/lot strange as you should be editing only the one <code>Organisation</code>...</p> <pre><code>public ActionResult Edit(int id) { // get your organisations from your orgRepo... I'm mocking that out. var orgs = new List&lt;Organization&gt; { new Organization { PartyId = 1, Description = "Org 1", Caption = "Caption 1", NameInUse = "Name 1"}, new Organization { PartyId = 2, Description = "Org 2", Caption = "Caption 2", NameInUse = "Name 2"}}; return View(orgs); } </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