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:
@model IEnumerable<WebWareApp.ViewModels.OstukorvVM>
@{
ViewBag.Title = "Ostukorv";
}
<h2>Hetkel ostukorvis olevad tooted:</h2>
@using (Html.BeginForm("Create", "ToodeTellimuses"))
{ @Html.AntiForgeryToken()
<table>
<tr>
<th>Tootenimi</th>
<th>Tootegrupp</th>
<th>Tootja</th>
<th>Mõõdud</th>
<th>Varvus</th>
<th>Hind</th>
<th>Vali Kogus</th>
<th></th>
</tr>
@{if (Model != null)
{
foreach (var item in Model)
{<tr>
<td>
@Html.DisplayFor(modelitem => item.Toode.Nimi)
@Html.HiddenFor(modelitem => item.Toode.Nimi)
</td>
<td>
@Html.DisplayFor(modelitem => item.Toode.Tootegrupp.Nimetus)
@Html.HiddenFor(modelitem => item.Toode.Tootegrupp.Nimetus)
</td>
<td>
@Html.DisplayFor(modelitem => item.Toode.Tootja)
@Html.HiddenFor(modelitem => item.Toode.Tootja)
</td>
<td>
@Html.DisplayFor(modelitem => item.Toode.Pikkus) x @Html.DisplayFor(modelitem => item.Toode.Laius) x @Html.DisplayFor(modelitem => item.Toode.Korgus)
@Html.HiddenFor(modelitem => item.Toode.Pikkus) @Html.HiddenFor(modelitem => item.Toode.Laius) @Html.HiddenFor(modelitem => item.Toode.Korgus)
</td>
<td>
@Html.DisplayFor(modelitem => item.Toode.Varvus)
@Html.HiddenFor(modelitem => item.Toode.Varvus)
</td>
<td>
@Html.DisplayFor(modelitem => item.Toode.Hind)
@Html.HiddenFor(modelitem => item.Toode.Hind)
</td>
<td>
@Html.EditorFor(modelitem => item.kogus)
</td>
<td>
@String.Format("Laos olemas {0}",item.Toode.Kogus)
@Html.HiddenFor(modelitem => item.Toode.Kogus)
</td>
</tr>
}
}}
</table>
<input type="submit" value="Telli">
}
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.