我使用Kendo Date Picker来计算会计月份,该字段是文本字段,我想使用DatePicker来选择月份和年份,并显示为'052020'作为文本
但是当我选择数据时,它将日期显示为Tue Jun 09 2020 00:00:00 GMT-0700 (Pacific Daylight Time)
,我如何获得一个月和一个日期。
在我的网格中,我有这个
new GridColumnSettings
{
Member = nameof(Sales.AcountingMonth),
MemberType = typeof(string),
Title = "Acounting Month",
},
并在我的弹出窗口中
@(Html.Kendo().DatePicker()
.Name(nameof(Sales.AcountingMonth))
.Format("MMMyyyy")
.Value(nameof(Sales.AcountingMonth))
)
答案 0 :(得分:0)
据我了解,您需要一种从c#MMYYYY
对象中获取DateTime
格式的字符串的方法。好吧,您可以执行此操作,如果您通过DateTime.ToString()
方法,则可以以所需的格式提供给它,它将产生结果字符串。在您的情况下,将是这样的:
@(
Html.Kendo()
.DatePicker()
.Name(nameof(Sales.AcountingMonth))
.Format("MMMyyyy")
.Value(Sales.AcountingMonth.ToString("MMMyyyy"))
// I assume AccountingMonth is of type DateTime.
// Notice, I removed the nameof call that you were making,
// which eventually was returning the name of the property that you were referencing.
)
PS:我只记得我回答了一个类似的问题,几天前“ YOU”问了这个问题,与这个问题非常相似。选中this answer.