我正在使用带有模型绑定和实体框架 5 的 .net 4.5 WebForms。
我的网络表单的一部分:
<asp:ListView ID="MenteeModuleList" ItemPlaceholderID="itemPlaceHolder"
OnCallingDataMethods="MenteeModuleList_CallingDataMethods"
ItemType="PFA_Mentorship.BLL.MenteeModuleBL+MenteeModuleGrid"
DataKeyNames="MenteeModuleID"
SelectMethod="GetMenteeModulesGrid"
InsertItemPosition="LastItem"
InsertMethod="InsertMenteeModule"
runat="server">
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<th id="Th1" runat="server">Module</th>
<th id="Th2" runat="server">Start Date</th>
<th id="Th3" runat="server">Due Date</th>
<th runat="server"></th>
</tr>
<tr runat="server" id="itemPlaceHolder"></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="tr1" runat="server">
<td runat="server">
<asp:Label runat="server" ID="moduleName" Text="<%#: BindItem.ModuleName %>"></asp:Label>
</td>
<td id="tr2" runat="server">
<asp:Label runat="server" ID="startDate" Text="<%#: BindItem.StartDate %>"></asp:Label>
</td>
<td id="td3" runat="server">
<asp:Label runat="server" ID="dueDate" Text="<%#: BindItem.DueDate %>"></asp:Label>
</td>
<td runat="server">
<asp:LinkButton runat="server" ID="Edit" CommandName="Edit" CommandArgument="<%#: BindItem.MenteeModuleID %>" Text="Edit" />
</td>
</tr>
</ItemTemplate>
<InsertItemTemplate>
</InsertItemTemplate>
<EditItemTemplate>
<tr>
<td id="Td1" runat="server">
<asp:Label ID="moduleName" runat="server" Text="<%#: BindItem.ModuleName %>"></asp:Label>
</td>
<td id="tr2" runat="server">
<asp:TextBox ID="startDate" runat="server" Text="<%#: BindItem.StartDate %>"></asp:TextBox>
</td>
<td id="td3" runat="server">
<asp:TextBox ID="dueDate" runat="server" text="<%#: BindItem.DueDate %>"></asp:TextBox>
</td>
<td>
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
我绑定到的实体:
public class MenteeModuleGrid
{
public int MenteeModuleID { get; set; }
public string ModuleName { get; set; }
public int MenteeID { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy/MM/dd}")]
public System.DateTime StartDate { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy/MM/dd}")]
public System.DateTime DueDate { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy/MM/dd}")]
public Nullable<System.DateTime> CompletedDate { get; set; }
}
尽管有数据注释,但日期字段在查看模式和编辑模式下显示为“2013/01/01 12:00:00 AM”。
我究竟做错了什么?