Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC passing IEnumerable<CustomVM> to Controller
    text
    copied!<p>Can someone help me to solve this problem. I want to pass ienumerable or just simple list of my custom viewmodel to controller. Theres my code: </p> <pre><code>@model IEnumerable&lt;WebWareApp.ViewModels.OstukorvVM&gt; @{ ViewBag.Title = "Ostukorv"; } &lt;h2&gt;Hetkel ostukorvis olevad tooted:&lt;/h2&gt; @using (Html.BeginForm("Create", "ToodeTellimuses")) { @Html.AntiForgeryToken() &lt;table&gt; &lt;tr&gt; &lt;th&gt;Tootenimi&lt;/th&gt; &lt;th&gt;Tootegrupp&lt;/th&gt; &lt;th&gt;Tootja&lt;/th&gt; &lt;th&gt;Mõõdud&lt;/th&gt; &lt;th&gt;Varvus&lt;/th&gt; &lt;th&gt;Hind&lt;/th&gt; &lt;th&gt;Vali Kogus&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;/tr&gt; @{if (Model != null) { foreach (var item in Model) {&lt;tr&gt; &lt;td&gt; @Html.DisplayFor(modelitem =&gt; item.Toode.Nimi) @Html.HiddenFor(modelitem =&gt; item.Toode.Nimi) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelitem =&gt; item.Toode.Tootegrupp.Nimetus) @Html.HiddenFor(modelitem =&gt; item.Toode.Tootegrupp.Nimetus) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelitem =&gt; item.Toode.Tootja) @Html.HiddenFor(modelitem =&gt; item.Toode.Tootja) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelitem =&gt; item.Toode.Pikkus) x @Html.DisplayFor(modelitem =&gt; item.Toode.Laius) x @Html.DisplayFor(modelitem =&gt; item.Toode.Korgus) @Html.HiddenFor(modelitem =&gt; item.Toode.Pikkus) @Html.HiddenFor(modelitem =&gt; item.Toode.Laius) @Html.HiddenFor(modelitem =&gt; item.Toode.Korgus) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelitem =&gt; item.Toode.Varvus) @Html.HiddenFor(modelitem =&gt; item.Toode.Varvus) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelitem =&gt; item.Toode.Hind) @Html.HiddenFor(modelitem =&gt; item.Toode.Hind) &lt;/td&gt; &lt;td&gt; @Html.EditorFor(modelitem =&gt; item.kogus) &lt;/td&gt; &lt;td&gt; @String.Format("Laos olemas {0}",item.Toode.Kogus) @Html.HiddenFor(modelitem =&gt; item.Toode.Kogus) &lt;/td&gt; &lt;/tr&gt; } }} &lt;/table&gt; &lt;input type="submit" value="Telli"&gt; } </code></pre> <p>But the problem is that in my controller when i debugg the incoming model fields are always null.If necessary i can post my viewmodel and models and controller to here also.</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