我正在尝试构建一个动态的System.DateTime列表,该列表也绑定到包含其他属性的模型。简化模型如下所示:
public class MAbsence : ModelBase<MAbsence, Absence>
{
public MAbsence ()
{
ExtraDates = new List<DateTime>();
}
....
[Display(Name = "Date extra")]
public List<DateTime> ExtraDates { get; set; }
}
我使用局部视图渲染ExtraDates,它看起来像这样:
@model System.DateTime
@{
Random rand = new Random();
var Index = rand.Next();
}
@using(Html.BeginCollectionItem("ExtraDates")){
<div class="ExtraDate" id="@Index">
<div class="form-group form-group-default " id="@Index">
@Html.LabelFor(model => model.Date)
<input name="Date" id="Date_@Index" type="text" class="form-control value="@Model.ToString("dd.MM.yyyy")"/>
@Html.ValidationMessageFor(M => M.Date, null, new { @class = "error" })
</div>
<a href="#" class="deleteRow">delete</a>
</div>
}
在[HttpPost]动作中,我试图将模型和模型以及IEnumerable ExtraDates作为参数,但它们都没有获得任何值。它们都是空的。
[HttpPost]
public ActionResult AbsenceAdd(MAbsence model, IEnumerable<DateTime> ExtraDates)
{
... code that should process the list of dates and the MAbsence model. Both lists model.ExtraDates and ExtraDates are null.
}
我错过了什么?