Question

In my model :

 public class WzDetail
    {
        public Product Product { get; set; }
        public bool check { get; set; }
        public int PlanQuantity { get; set; }
        public int RealQuantity { get; set; }
    }
public class Wz
{
   public IList<WzDetail> WzMain { get; set; }
   public IList<WzDetail> WzAdditional { get; set; }
   public IList<WzDetail> WzEquipment { get; set; }
   public string SignatureOne { get; set; }
   public string SignatureTwo { get; set; }
}

As you can see there are a list. Displays it in a simple way:

            <table class="table1" >
         @Html.EditorFor(x => x.WzEquipment) 
            </table>

My EditorTemplates:

    @model WzDetail

<tr>
    @Html.HiddenFor(x => x.Product.BarCode)
    @Html.HiddenFor(x => x.Product.Checked)
    @Html.HiddenFor(x => x.Product.ProductGroup)
    @Html.HiddenFor(x => x.Product.ProductId)
    @Html.HiddenFor(x => x.Product.Weight)
    <td>@Model.Product.ProductName </td>  
    <td>@Model.PlanQuantity</td>
    <td>@Html.TextBoxFor(m => m.RealQuantity, new { type = "range", pattern = "[0-9]*", min = "0", max = @Model.PlanQuantity*2, Value = @Model.PlanQuantity })</td>
    <td align="right" ><label class="mylabel" data-theme="c" for="@Model.Product.ProductId" data-iconpos="right" >&nbsp;</label>
    @Html.CheckBoxFor(m => m.check, new { type = "checkbox", id = @Model.Product.ProductId, @class = "mychck" })
</tr>
@Html.ValidationMessageFor(m => m.RealQuantity)

Everything is well displayed.

but after post model to controller, every time the lists are empty even though when generating the view is complete.

This is the code generated by jQuery Mobile on client side:

<table class="table1">
<tbody>
<tr>
<input id="WzMain_0__Product_BarCode" type="hidden" value="" name="WzMain[0].Product.BarCode">
<input id="WzMain_0__Product_Checked" type="hidden" value="False" name="WzMain[0].Product.Checked" data-val-required="The Checked field is required." data-val="true">
<input id="WzMain_0__Product_ProductGroup" type="hidden" value="Main" name="WzMain[0].Product.ProductGroup" data-val-required="The ProductGroup field is required." data-val="true">
<input id="WzMain_0__Product_ProductId" type="hidden" value="4" name="WzMain[0].Product.ProductId" data-val-required="The ProductId field is required." data-val-number="The field ProductId must be a number." data-val="true">
<input id="WzMain_0__Product_Weight" type="hidden" value="0" name="WzMain[0].Product.Weight" data-val-required="The Weight field is required." data-val-number="The field Weight must be a number." data-val="true">
<td>Woda 18,9L </td>
<td>1</td>
<td>
<input id="WzMain_0__RealQuantity" class="ui-input-text ui-body-a ui-corner-all ui-shadow-inset ui-slider-input" type="number" data-type="range" pattern="[0-9]*" name="WzMain[0].RealQuantity" min="0" max="2" data-val-required="The Zrealizowana ilość field is required." data-val-regex-pattern="^-?\d+$" data-val-regex="Ilość można podać tylko liczbowo" data-val-range-min="0" data-val-range-max="999" data-val-range="Zakres od 1 do 999" data-val-number="The field Zrealizowana ilość must be a number." data-val="true" value="1">
<div class="ui-slider ui-btn-down-a ui-btn-corner-all" role="application">
<a class="ui-slider-handle ui-btn ui-btn-up-a ui-btn-corner-all ui-shadow" href="#" data-corners="true" data-shadow="true" data-iconshadow="true" data-inline="false" data-wrapperels="span" data-theme="a" role="slider" aria-valuemin="0" aria-valuemax="2" aria-valuenow="1" aria-valuetext="1" title="1" aria-labelledby="WzMain_0__RealQuantity-label" style="left: 50%;">
<span class="ui-btn-inner">
<span class="ui-btn-text"></span>
</span>
</a>
</div>
</td>
<td align="right">
<div class="ui-checkbox">
<input id="4" class="mychck" type="checkbox" value="true" name="WzMain[0].check" data-val-required="The Zaznaczony field is required." data-val="true">
<label class="mylabel ui-btn ui-btn-up-c ui-btn-icon-right ui-checkbox-off" data-iconpos="right" for="4" data-theme="c" data-corners="true" data-shadow="false" data-iconshadow="true" data-inline="false" data-wrapperels="span" data-icon="checkbox-off">
<span class="ui-btn-inner">
<span class="ui-btn-text">&nbsp;</span>
<span class="ui-icon ui-icon-checkbox-off ui-icon-shadow"></span>
</span>
</label>
</div>
<input type="hidden" value="false" name="WzMain[0].check">
</td>
</tr>
</tbody>
</table>

Any idea how to send list to controller ?

Was it helpful?

Solution 2

OK. my bad i try to post like that:

@using (Html.BeginForm("DocumentConfirmation", "Order", @Model, FormMethod.Post))

But correct is:

@using (Html.BeginForm("DocumentConfirmation", "Order", FormMethod.Post))

OTHER TIPS

the controller that receive the action should have a parameter named WzMain of type IEnumerable<WzDetail>

try it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top