1
與MVC 4
&工作,我創建了一個編輯模板從DateTime
對象MVC 4編輯模板在HH顯示時間:mm格式
編輯模板代碼(TimePicker.cshtml)
在HH:mm
格式,只顯示時間
@model DateTime?
@{
String modelValue = "";
var dateFormat = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat;
var id = "";
var cls = "";
var style = "";
var placeholder = "";
if (ViewData["_id"] != null)
{
id = (string)ViewData["_id"];
}
if (ViewData["_class"] != null)
{
cls = (string)ViewData["_class"];
}
if (ViewData["_style"] != null)
{
style = (string)ViewData["_style"];
}
if (ViewData["_placeholder"] != null)
{
placeholder = (string)ViewData["_placeholder"];
}
if (Model.HasValue)
{
if (Model.Value != DateTime.MinValue)
{
modelValue = Model.Value.ToString("HH:mm", dateFormat);
}
}
}
@Html.TextBox("", modelValue,
new { @class = cls, @id = id, @style = style, @placeholder = placeholder })
在查看
@Html.EditorFor(m => m.StartTime, "TimePicker", new { _id = "StartTime"})
但是呈現最終的HTML是
<input id="StartTime" name="StartTime" type="text" value="2013-08-05 0:00:00" />
即使我用力編碼調試的值類似下面
@Html.TextBox("", "00:00",
new { @class = cls, @id = id, @style = style, @placeholder = placeholder })
我仍然得到同樣的2013-08-05 0:00:00
代替0:00
什麼是代碼的問題?
編輯:在快速查看adding name parameter
以TextBox給出結果。但它附加了名稱屬性,我不想要。找到這個截圖