在我的模特中:
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; }
}
如您所见,有一个列表。以简单的方式显示它:
<table class="table1" >
@Html.EditorFor(x => x.WzEquipment)
</table>
我的编辑模板:
@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" > </label>
@Html.CheckBoxFor(m => m.check, new { type = "checkbox", id = @Model.Product.ProductId, @class = "mychck" })
</tr>
@Html.ValidationMessageFor(m => m.RealQuantity)
一切都很好。
但是在将模型发布到控制器之后,每次列表都是空的,即使生成视图已经完成。
这是jQuery Mobile在客户端生成的代码:
<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"> </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>
知道如何将列表发送给控制器吗?
答案 0 :(得分:1)
接收操作的控制器应具有WzMain
类型IEnumerable<WzDetail>
的参数
试试吧
答案 1 :(得分:0)
行。 我的错 我试着这样发帖:
@using (Html.BeginForm("DocumentConfirmation", "Order", @Model, FormMethod.Post))
但正确的是:
@using (Html.BeginForm("DocumentConfirmation", "Order", FormMethod.Post))