我一直在寻找这个网站的一些答案我的问题,我找到了一些相关的,但任何解决我的烦恼。我将不胜感激任何帮助。 我从我的控制器发送一个列表到视图,我得到它填充,但当我将它发送回控制器时,我得到它为空(Count = 0)。
这是我的模特......
public class PriceListIndex
{
public List<PriceList> PriceLists { get; set; }
public List<NewPriceList> NewPriceLists { get; set; }
public int BlindTypeId { get; set; }
public string BlindType { get; set; }
public int GroupId { get; set; }
public string Group { get; set; }
}
以下是我的观点......
@model A_Palace_Interior.ViewModel.PriceListIndex
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm("Create", "PriceLists",FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new {@class = "text-danger"})
@Html.HiddenFor(model => model.BlindTypeId)
@Html.HiddenFor(model => model.GroupId)
@Html.HiddenFor(model => model.PriceLists)
@Html.HiddenFor(model => model.NewPriceLists)
<h4>Price List</h4>
<h5>Blind Type: @Model.BlindType</h5>
<h5>Group: @Model.Group</h5>
<table class="table-bordered">
@{
List<double> widths = ViewBag.Width;
List<double> heights = ViewBag.Height;
}
<tr>
<th rowspan="2" style="align-content: center">Length</th>
<th colspan=@widths.Count style="align-content: center">Width</th>
</tr>
<tr>
@{
foreach (var width in widths)
{
<td>@width</td>
}
}
</tr>
@{
foreach (var height in heights)
{
<tr>
<td>@height</td>
@foreach (var width in widths)
{
if (Model.PriceLists.Exists(pl => pl.BlindDimensions.Width == width && pl.BlindDimensions.Height == height))
{
var priceList = Model.PriceLists.Find(pl => pl.BlindDimensions.Width == width && pl.BlindDimensions.Height == height);
<td>
@Html.EditorFor(model=>priceList.Price)
@Html.ValidationMessageFor(model => priceList.Price, "", new {@class = "text-danger"})
</td>
}
else
{
var newPriceList = new NewPriceList();
newPriceList.Height = height;
newPriceList.Width = width;
Model.NewPriceLists.Add(newPriceList);
<td>
@Html.EditorFor(model => model.NewPriceLists.Last().Price)
@Html.ValidationMessageFor(model => model.NewPriceLists.Last().Price, "", new {@class = "text-danger"})
</td>
}
}
</tr>
}
}
</table>
<input type="submit" value="Save" class="btn btn-default"/>
这是我的控制器......
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create(PriceListIndex priceListIndex)
{
if (ModelState.IsValid)
{
//code here
}
}
提前致谢...