格式化的日期TextBoxFor

编程入门 行业动态 更新时间:2024-10-20 07:45:29
本文介绍了格式化的日期TextBoxFor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我安装了ASP.NET MVC3。我需要用日期选择器格式的日期。我想这一点,但它不工作(路过的时候{0:DD / MM / YYYY}作为format参数,它仍然不格式):

I have ASP.NET MVC3 installed. I need datepicker with formatted date. I tried this, but it's not working (when passing "{0:dd/MM/yyyy}" as format parameter, it still does not format):

private static MvcHtmlString FormattedDateTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string format, RouteValueDictionary htmlAttributes) { var metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); if (metadata.Model != null && metadata.Model as DateTime? != null) htmlAttributes.Add("value", string.Format(format, (DateTime)metadata.Model)); return htmlHelper.TextBoxFor(expression, htmlAttributes); }

编辑:我的code工作,如果格式为{0:DD-MM-YYYY},但不仅为{0:DD / MM / YYYY}

My code works if format is "{0:dd-MM-yyyy}" but not only for "{0:dd/MM/yyyy}"

我知道MVC4已经有这个功能,但遗憾的是我的项目是写在MVC3。你能帮助我吗?

I know that MVC4 has already this functionality, but unfortunately my project is written on MVC3. Can you help me?

推荐答案

我甚至已经得到了工作的唯一格式是这样的:

The only format I have even gotten to work is this:

@Html.TextBoxFor(m => m.Birthdate, "{0:MM/dd/yyyy}")

更多推荐

格式化的日期TextBoxFor

本文发布于:2023-10-25 08:31:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1526454.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   TextBoxFor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!