在编辑模式MVC中从日期选择器中删除时间 [英] Remove time from datepicker in Edit mode MVC
问题描述
我尝试了不同的代码来解决此问题,但是它们并不能完全按照我的要求工作.我已经尝试过
I tried different pieces of code to solve this issue but they don't work exactly how I want. I've tried
@Html.TextBoxFor(model => model.Date, "{0:MM/dd/yyyy}", new { id="datepicker" })
和
在使用jquery时将TextBoxFor更改为EditorFor
changing my TextBoxFor to EditorFor while using jquery
$("#datepicker1").datepicker({ dateFormat: "dd-mm-yy", changeMonth: true, changeYear: true });
当我执行这些操作中的任何一个时,日期都会返回没有时间的正常值(例如4-12-14),但是我松开了日期选择器日历的功能.如果我不使用它们,我的日期选择器日历可以正常工作,但是最终在编辑文本框中显示4-12-14 00:00:00.
When I do either of these the date returns fine without the time (i.e 4-12-14), however I loose the functionality of my datepicker calendar. If I don't use them my datepicker calendar works fine however I end up with 4-12-14 00:00:00 in my edit textbox.
The code from my Model is:
[Display(Name = "Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> Date { get; set; }
有什么办法解决这个问题吗?
Any ideas how to solve this?
推荐答案
它解决了我需要做的所有事情,就是将文本框的格式更改为
Got it solved all I needed to do was change the formatting of my textbox to
@Html.TextBoxFor(model => model.LRRRentReviewDate, "{0:d/M/yyyy}", new { id="datepicker" })
和我的模型日期格式为
[Display(Name = "Date")]
[DisplayFormat(DataFormatString = "{0:d/M/yyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> Date { get; set; }
再次
出于个人目的,我需要在代码中使用public nullable.我的JQuery很好,不需要任何更改.
again I needed to use public nullable in my code for my own purposes. My JQuery was fine and didn't need any alterations.
这篇关于在编辑模式MVC中从日期选择器中删除时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!