Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET数据绑定多种格式_C#_Date_Webforms_Entity Framework 5 - Fatal编程技术网

C# ASP.NET数据绑定多种格式

C# ASP.NET数据绑定多种格式,c#,date,webforms,entity-framework-5,C#,Date,Webforms,Entity Framework 5,我有一个使用EF5的ASP.NET4.5Web表单网站 我的数据模型的一个对象是具有DateTime属性的“医疗文件”(除其他外): 众所周知,上面的TryUpdateModel(medfile)自动神奇地验证、解析和转换web表单中的字段,更新传递的medfile变量 特别是,它根据web.config文件中可能设置的应用程序区域性的日期格式验证和转换TextBox2的值: <globalization culture="it-IT" uiCulture="it-IT" />

我有一个使用EF5的ASP.NET4.5Web表单网站

我的数据模型的一个对象是具有DateTime属性的“医疗文件”(除其他外):

众所周知,上面的TryUpdateModel(medfile)自动神奇地验证、解析和转换web表单中的字段,更新传递的medfile变量

特别是,它根据web.config文件中可能设置的应用程序区域性的日期格式验证和转换TextBox2的值:

<globalization culture="it-IT" uiCulture="it-IT" />

我的问题是,我希望用户能够使用两种可能的格式之一设置Web表单中的日期:默认区域性格式,在我的例子中是dd/MM/yyyy(意大利)和国际yyyy-MM-dd(ISO 8601)


是否可以指示TryUpdateModel(TModel)同时“接受”这两种格式?

您的问题特定于日期,但代码中没有显示任何日期。我们没有水晶球来告诉我们您的模型厕所是什么样的,或者您的业务逻辑是什么。我们只知道你在这里发布的内容。请编辑您的问题,使其可重复,并说明您所描述的具体问题。谢谢,对不起。我重写了上面的问题。现在我希望它足够清楚。
<asp:ListView ID="MedFilesForm" runat="server" 
    ItemType="MedFile" DataKeyNames="MedFileId" 
    SelectMethod="GetFiles"
    UpdateMethod="UpdateFile">
    ...
    <EditItemTemplate>
        <asp:Label ID="Label1" runat="server" AssociatedControlID="TextBox1">Name</asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>' />

        <asp:Label ID="Label2" runat="server" AssociatedControlID="TextBox2">Data</asp:Label>
        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("MedDate", "{0:d}") %>' />

        <asp:LinkButton ID="UpdateButton" runat="server"
            CausesValidation="true" CommandName="Update"
        </asp:LinkButton>
    </EditItemTemplate>
</asp:ListView>
public void UpdateFile(Guid medFileId) {
    // get the current med file from DB
    MedFile medfile = _cartellaBLL.GetMedFileByFileId(medFileId);
    // update it with values taken from the web form
    TryUpdateModel(medfile);
    // save the updated med file
    if (ModelState.IsValid) {
       _cartellaBLL.UpdateFile(medfile);
    }
    ...
}
<globalization culture="it-IT" uiCulture="it-IT" />