ビューから DateTime のコレクションを渡そうとしています:
@Html.ActionLink("Hello", "Index", "Home", new { dates = new Collection(){date1, date2)} })
これが私の行動です:
[HttpGet]
public ActionResult Index(int? page, string searchString, ICollection<DateTime> dates)
{ ...
しかし、日付では常に null になります。助言がありますか?
アップデート
問題は、間違った URL を作成すると思うことです:
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)
{ ...