<i id='i6B21'><tr id='i6B21'><dt id='i6B21'><q id='i6B21'><span id='i6B21'><b id='i6B21'><form id='i6B21'><ins id='i6B21'></ins><ul id='i6B21'></ul><sub id='i6B21'></sub></form><legend id='i6B21'></legend><bdo id='i6B21'><pre id='i6B21'><center id='i6B21'></center></pre></bdo></b><th id='i6B21'></th></span></q></dt></tr></i><div id='i6B21'><tfoot id='i6B21'></tfoot><dl id='i6B21'><fieldset id='i6B21'></fieldset></dl></div>

        <bdo id='i6B21'></bdo><ul id='i6B21'></ul>
        <legend id='i6B21'><style id='i6B21'><dir id='i6B21'><q id='i6B21'></q></dir></style></legend><tfoot id='i6B21'></tfoot>

        <small id='i6B21'></small><noframes id='i6B21'>

        如何格式化 MVC3 中 TextBoxFor() 显示的 DateTime?

        How do you format a DateTime that#39;s displayed by TextBoxFor() in MVC3?(如何格式化 MVC3 中 TextBoxFor() 显示的 DateTime?)

        <small id='rsSmQ'></small><noframes id='rsSmQ'>

            • <i id='rsSmQ'><tr id='rsSmQ'><dt id='rsSmQ'><q id='rsSmQ'><span id='rsSmQ'><b id='rsSmQ'><form id='rsSmQ'><ins id='rsSmQ'></ins><ul id='rsSmQ'></ul><sub id='rsSmQ'></sub></form><legend id='rsSmQ'></legend><bdo id='rsSmQ'><pre id='rsSmQ'><center id='rsSmQ'></center></pre></bdo></b><th id='rsSmQ'></th></span></q></dt></tr></i><div id='rsSmQ'><tfoot id='rsSmQ'></tfoot><dl id='rsSmQ'><fieldset id='rsSmQ'></fieldset></dl></div>
              <tfoot id='rsSmQ'></tfoot>

              • <bdo id='rsSmQ'></bdo><ul id='rsSmQ'></ul>
                1. <legend id='rsSmQ'><style id='rsSmQ'><dir id='rsSmQ'><q id='rsSmQ'></q></dir></style></legend>
                    <tbody id='rsSmQ'></tbody>
                  本文介绍了如何格式化 MVC3 中 TextBoxFor() 显示的 DateTime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我已经安装了 ASP.NET MVC3.我需要带有格式化日期的日期选择器.我试过这个,但它不起作用(当传递{0:dd/MM/yyyy}"作为格式参数时,它仍然不格式化):

                  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);
                      }
                  

                  如果格式为{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}")
                  

                  这篇关于如何格式化 MVC3 中 TextBoxFor() 显示的 DateTime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
                  Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
                  Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
                  How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
                  how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
                  JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)
                  <tfoot id='juC4g'></tfoot>
                  1. <small id='juC4g'></small><noframes id='juC4g'>

                          <tbody id='juC4g'></tbody>

                          • <bdo id='juC4g'></bdo><ul id='juC4g'></ul>

                            <legend id='juC4g'><style id='juC4g'><dir id='juC4g'><q id='juC4g'></q></dir></style></legend>
                            <i id='juC4g'><tr id='juC4g'><dt id='juC4g'><q id='juC4g'><span id='juC4g'><b id='juC4g'><form id='juC4g'><ins id='juC4g'></ins><ul id='juC4g'></ul><sub id='juC4g'></sub></form><legend id='juC4g'></legend><bdo id='juC4g'><pre id='juC4g'><center id='juC4g'></center></pre></bdo></b><th id='juC4g'></th></span></q></dt></tr></i><div id='juC4g'><tfoot id='juC4g'></tfoot><dl id='juC4g'><fieldset id='juC4g'></fieldset></dl></div>