In my EditorTemplates, I have DateTime.cshtml - which works find in create/edit/update views:
@model Nullable<System.DateTime>
@if ( Model.HasValue ) {
@Html.TextBox( "" , String.Format( "{0:dd/MM/yyyy}" , Model.Value ) , new { @class = "datepicker span2" } )
}
else {
@Html.TextBox( "" , String.Format( "{0:dd/MM/yyyy}" , DateTime.Now ) , new { @class = "datepicker span2" } )
}
When creating a search view, I also want to use a datetime picker - how would I code the view use the code above, when it's not linked to a model, but just plain HTML?
If I just enter the following into my Razor markup:
@using (Html.BeginForm())
{
<p>
Availability between: @Html.TextBox( "From" , String.Format( "{0:dd/MM/yyyy}") , new { @class = "datepicker span2" } )
and: @Html.TextBox( "To" , String.Format( "{0:dd/MM/yyyy}") , new { @class = "datepicker span2" } )
<input type="submit" value="Search" /></p>
}
I just get the error:
{"Index (zero based) must be greater than or equal to zero and less than the size of the argument list."}
Thanks for any help,
Mark