ASP.NET MVC2和日期时间格式 [英] ASP.NET MVC2 and DateTime Format

查看:196
本文介绍了ASP.NET MVC2和日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET MVC2与MvcContrib.FluentHtml做形式结合。

I am using ASP.NET MVC2 with MvcContrib.FluentHtml to do form binding.

我想一个DateTime格式绑定到特定日期时间格式的文本框。

I want to bind a DateTime format to a textbox with specific datetime format.

<%=this.TextBox(c => c.date_a).Class("readonly text-box") %>
// PS. c.date_a is a DateTime

给我

<input type="text" value="5/9/2009 12:00:00 AM" name="date_a" id="datea" class="readonly text-box">

不过,我想覆盖默认的日期时间格式。
例如

However, I'd like to override the default datetime format. e.g.

value="2009-5-9" 
value="9-5-09" 
value="09May9" 

我知道我可以通过特定的值覆盖值,不过,日期也应该绑定到POST的对象类的形式。

I know I can override the value by specific a value, however, the date should also bind to the object class on POST the form.

如何做到最低code覆盖特定字段的默认日期时间格式上的用户界面?

How to do "minimum" code to override the default datetime format of a specific field on UI?

推荐答案

通过FluentHtml你可以这样做:

With FluentHtml you can do like this:

<%=this.TextBox(c => c.date_a).Class("readonly text-box").Format("yyyy-M-d") %>

这篇关于ASP.NET MVC2和日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆