I have an action like this
public ActionResult Overview(TimeAxisVM TimeAxis = null)
{
return View(new OverviewVM());
}
Show a model like this
public class TimeAxisVM
{
[DataType(DataType.DateTime)]
public DateTime? From { get; set; }
[DataType(DataType.DateTime)]
public DateTime? To { get; set; }
}
Editor Template for Presentation Model
@model TimeAxisVM
@using (Html.BeginForm("Overview", "Controller", FormMethod.Get))
{
@Html.EditorFor(model => model.From)
@Html.EditorFor(model => model.To)
<button type="submit">Submit</button>
}
And a view for the Browse action like this
@model OverviewVM
@Html.EditorFor(model => model.TimeAxis)
When I execute the GET request, this is the query string TimeAxis.From = 22. + 02. + 2014 & TimeAxis.To = 25. + 02. + 2014, but once in action TimeAxis.From and TimeAxis.To are equal to zero.
If I change the form method to POST, it immediately works as expected. From a design point of view, this should / should be a GET request.
Any ideas on how to make model binding work for GET?
UPDATE:
Change action to
public ActionResult Overview(DateTime? From = null, DateTime? To = null)
and sending a request in this form: ... / Browse /? From = 22. + 02. + 2014 & To = 25. + 02. + 2014 also works.
, - EditorFor TimeAxis.From TimeAxis.To. ViewModel/form.