【发布时间】:2016-02-29 13:11:51
【问题描述】:
我在我的 mvc 6 项目中使用带有 taghelper 元素的“asp-format”标签时遇到问题。
这个想法是这样格式化一个日期输入元素:
<input asp-for="StartDate" asp-format="{0:dd/MM/yyyy}" />
这个“StartDate”属性在我的模型中,这样声明:
public DateTime StartDate {get; set; }
出于一个奇怪的原因,这个元素从来没有被格式化,并且总是这样显示:
---> 02/29/2016 00:00:00
所以我创建了一个视图模型类并定义了一个属性来保存整个人物模型。
public class PersonViewModel
{
public Person Johndoe {get; set; }
}
在视图中使用这个类,格式化工作。
<input asp-for="Johndoe.StartDate" asp-format="{0:dd/MM/yyyy}" />
---> 29/02/2016
【问题讨论】:
-
你有没有使用标签助手解决这个问题?我只是尝试按照您在问题开始时的方式进行操作,并且对我有用。
标签: c# asp.net asp.net-mvc datetime-format