开发者

Format Time to HH:mm C# + MVC 2

I want 'Time' to be displayed as HH:mm on UI (editable mode)

my code so far :

    [DisplayName("JobProcessEndTime")]
    [Required(ErrorMessage = "Is required field. Format HH:MM (24 hour time)")]
    [DisplayFormat(ApplyFormatInEditMode = true开发者_如何转开发, DataFormatString = "{0:HH:mm}")]
    public TimeSpan JobProcessEndTime { get; set; }

in view

 <%-- <td class="data"><%=Html.TextBoxFor(model => model.JobProcessEndTime)%></td>--%>
            <td class="data"><%= Html.TextBox("JobProcessEndTime", string.Format("{0:HH:mm}", Model.JobProcessEndTime))%></td>

tried both ways in view. still it displays the 'seconds' part.


The format string should be

@"{0:hh\:mm}"

and either one of the method would work.


<td class="data">
    <%= Html.EditorFor(x => x.JobProcessEndTime) %>
</td>


To het this to work in MVC 3 I had to use Html.EditorFor instead of Html.TextBoxFor.

<td class="data">
    <%= Html.EditorFor(x => x.JobProcessEndTime) %>
</td>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜