在我的 EditorTemplates 中,我有 DateTime.cshtml - 它可以在创建/编辑/更新视图中找到:
@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" } )
}
创建搜索视图时,我还想使用日期时间选择器 - 当视图未链接到模型而只是纯 HTML 时,我将如何使用上面的代码对视图进行编码?
如果我只是在 Razor 标记中输入以下内容:
@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>
}
我只是得到错误:
{"Index (zero based) must be greater than or equal to zero and less than the size of the argument list."}
谢谢你的帮助,
标记