Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would recommend you using editor templates instead of writing any loops in your views:</p> <pre><code>&lt;% using (Html.BeginForm("makeTransfer", "shareTransfer")) { %&gt; &lt;%= Html.EditorFor(x =&gt; x.Inform) %&gt; &lt;%= Html.HiddenFor(x =&gt; x.accSrc, new { @value = Model.accSrc }) %&gt; &lt;%= Html.HiddenFor(x =&gt; x.accDst, new { @value = Model.accDst }) %&gt; Date of Transfer &lt;%= Html.TextBoxFor(x =&gt; x.date) %&gt; Transfer with benefit &lt;%= Html.CheckBoxFor(x =&gt; x.withBenefit) %&gt; &lt;input type="submit" name="save" value="Save" /&gt;&lt;/div&gt; &lt;input type="submit" name="cancel" value="Cancel" /&gt;&lt;/div&gt; &lt;% } %&gt; </code></pre> <p>and in the corresponding editor template (<code>~/Views/Shared/EditorTemplates/InformViewModel.ascx</code>):</p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;AppName.Models.InformViewModel&gt;" %&gt; &lt;%= Html.HiddenFor(x =&gt; x.shares) %&gt; ... &lt;td style="width:20px"&gt; &lt;%= Html.TextBoxFor(x =&gt; x.sharesRq) %&gt; &lt;/td&gt; </code></pre> <p>Remark: you might need to adjust the name of the editor template based on the type of the <code>Inform</code> property.</p> <p>Editor templates will take care of generating proper id and names of the input fields so that everything binds correctly:</p> <pre><code>[HttpPost] public ActionResult makeTransfer(vmTransfer transfer, string save, string cancel) { if (cancel != null) { return RedirectToAction("startTransfer"); } else if (save != null) { foreach (var t in transfer.Inform) { ... } } ... } </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