设置选择列表中项目的格式
我看过其他帖子,其中有对此问题的答案,但我无法让其中任何一个为我工作......所以。这是在我的控制器中->
ViewData["TARGET_DATE"] = new SelectList((from n in _db.ACTION_PLANs select n).ToList(), "TARGET_DATE", "TARGET_DATE");
我希望能够对从数据库返回的日期应用一种格式,我的 DDL 看起来像这样,
<td><%=Html.DropDownList("TARGET_DATE", "All")%></td>
有人知道是否有一种方法可以循环遍历并格式化每个日期,或者对所有日期应用一种格式。或者最好的方法是什么,如果您需要我可以提供的更多代码,我真正想要的是显示日期而不显示时间。提前致谢。
i have seen other posts with answers to this but i cannot get any of them to work for me.. so. this is in my controller->
ViewData["TARGET_DATE"] = new SelectList((from n in _db.ACTION_PLANs select n).ToList(), "TARGET_DATE", "TARGET_DATE");
i want to be able to apply a format on the dates that come back from the db, my DDL looks like this
<td><%=Html.DropDownList("TARGET_DATE", "All")%></td>
does anyone know if there is a way to loop through and format each date, or apply a format to them all. or what would be the best way to do this, if u need more code i can provide, what i really want is to display the date without the time with it. thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这篇文章很旧,但我在寻找同一问题的答案时遇到了它。我最终编写了一个 FormattableSelectList 类,它采用格式字符串作为参数,然后格式化选择列表的输出。这是如何使用它的示例。
我在 http: //www.jpolete.me/2011/11/16/a-formattable-selectlist-for-net-mvc/。这是它的代码。
I know this post is old, but I ran across it while searching for an answer to the same problem. I ended up writing a FormattableSelectList class that takes a format string as a parameter, and then formats that output of the select list. Here's a sample of how to use it.
I wrote a short post about it at http://www.jpolete.me/2011/11/16/a-formattable-selectlist-for-net-mvc/. Here's the code for it.
这是我如何实现上面的类。我的客户正在寻找两个包含开始时间和结束时间的下拉列表。在 MVC4
模型中:
控制器:
视图:
Here is how I implemented the class above. My client was looking for two dropdownlists containing Start time and End time. In MVC4
Model:
Controller:
View: