我正在尝试从我的视图中传递 DateTime 集合:
@Html.ActionLink("Hello", "Index", "Home", new { dates = new Collection(){date1, date2)} })
这是我的行动:
[HttpGet]
public ActionResult Index(int? page, string searchString, ICollection<DateTime> dates)
{ ...
但我总是在日期中得到空值。有什么建议么?
更新
问题是我认为它创建了不正确的网址:
http://localhost:39152/Home?dates=System.Collections.ObjectModel.Collection%601%5BSystem.DateTime%5D
顺便说一句,我补充说:
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
var date = value.ConvertTo(typeof (DateTime), CultureInfo.CurrentCulture);
return date;
}
并采取行动:
[HttpGet]
public ActionResult Index(int? page, string searchString, [ModelBinder(typeof (ModelBinders.DateTimeBinder))] ICollection<DateTime> dates)
{ ...