可空日期和空日期仍显示为1/1/0001

时间:2022-01-21 03:18:23

In my jqGrid, I want to have empty values in my grid...

在我的jqGrid中,我希望在我的网格中有空值...

Instead I am getting 1/1/0001

相反,我得到了1/1/0001

my model types for the dateTime are all nullable.

我的dateTime的模型类型都可以为空。

Am I missing something???

我错过了什么吗???

this is the code...

这是代码......

public DateTime? DischargeDateTime { get; set; }

What do you guys recommend?

你们推荐什么?

        tableToGrid("#frTable", {
            cmTemplate: { sortable: false },
            caption: '@TempData["POPNAME"]' + ' Population',
            height: '400',
            gridview: true,
            shrinkToFit: false,
            autowidth: true,
            colNames: ['Edit',
                   'MRN',
                   'Hospital Fin',
                   'First Name',
                   'Last Name',
                   'Date of birth',
                   'Completed Pathway',
                   'Completed Pathway Reason',
                   'PCP Appointment',
                   'Specialist Appointment',
                   'Admit Date',
                   'Discharge Date',
                   'Discharge Disposition',
                   'Discharge To',
                   'Discharge Advocate Call',
                   'Home Healthcare',
                   'Safe Landing Accepted',
                   'PCP Name',
                   'PCP Phone',
                   'PCP Appointment Location',
                   'Specialist Name',
                   'Specialist Phone',
                   'Specialist Appointment Location',
                   'Comments',
                   'Patient Room Phone',
                   'Phone',
                   'Payor',
                   'MRN Type'
                   ],
            colModel: [
                   { name: 'Edit', width: 95, align: 'left' },
                   { name: 'MRN', width: 125, align: 'left' },
                   { name: 'Hospital_Fin', width: 145, align: 'left' },
                   { name: 'First_Name', width: 115, align: 'left' },
                   { name: 'Last_Name', width: 115, align: 'left' },
                   { name: 'Date_of_birth', width: 145, align: 'left' },
                   { name: 'Completed_Pathway', width: 125, align: 'left', editOptions: {value:"1:Yes;0:No"} },
                   { name: 'Completed_Pathway_Reason', width: 165, align: 'left' },
                   { name: 'PCP_Appointment', width: 115, align: 'left' },
                   { name: 'Specialist_Appointment', width: 125, align: 'left' },
                   { name: 'Admit_Date', width: 185, align: 'left' },
                   { name: 'Discharge_Date', width: 185, align: 'left' },
                   { name: 'Discharge_Disposition', width: 155, align: 'left' },
                   { name: 'Discharge_To', width: 85, align: 'left' },
                   { name: 'Discharge_Advocate_Call', width: 155, align: 'left' },
                   { name: 'Home_Health_Care_Accepted', width: 105, align: 'left' },
                   { name: 'Safe_Landing_Accepted', width: 165, align: 'left' },
                   { name: 'PCP_Name', width: 85, align: 'left' },
                   { name: 'PCP_Phone', width: 85, align: 'left' }, // formatter: formatPhoneNumber,
                   { name: 'PCP_Appointment_Location', width: 185, align: 'left' },
                   { name: 'Specialist_Name', width: 195, align: 'left' },
                   { name: 'Specialist_Phone', width: 135, align: 'left' }, //, formatter: formatPhoneNumber
                   { name: 'Specialist_Appointment_Location', width: 185, align: 'left' },
                   { name: 'Comments', width: 185, align: 'left' },
                   { name: 'Patient_Room_Phone', width: 135, align: 'left' }, //, formatter: formatPhoneNumber
                   { name: 'Phone', width: 125, align: 'left' }, //, formatter: formatPhoneNumber
                   { name: 'Payor', width: 155, align: 'left' },
                   { name: 'MRN_Type', width: 135, align: 'left' }
                   ]
        });

There are indeed several nulls in my database that come back... Not sure why this doesn't work...

我的数据库确实有几个空值回来......不知道为什么这不起作用......

Currently trying a UIHint...

目前正在尝试UIHint ...

@if (Model == null){
    <text></text>
}else{
    <text></text>
}

except now everything is being displayed incorrectly

除了现在一切都显示不正确

1 个解决方案

#1


0  

Ok... I know what I was doing wrong. In my repository layer, I forgot I had a method that would take the string dates that were being pulled pack, parsed, and if the value was null I would set the minimum date.

好的......我知道我做错了什么。在我的存储库层中,我忘了我有一个方法可以将字符串日期拉到包,解析,如果值为null,我会设置最小日期。

I have now changed that so that it returns a null, or a parsed date...

我现在改变了它,以便返回null或解析日期......

    public static DateTime? ValueOrMin(string value)
    {
        if (string.IsNullOrWhiteSpace(value)) return null;
        return DateTime.Parse(value);
    }

Thanks.

#1


0  

Ok... I know what I was doing wrong. In my repository layer, I forgot I had a method that would take the string dates that were being pulled pack, parsed, and if the value was null I would set the minimum date.

好的......我知道我做错了什么。在我的存储库层中,我忘了我有一个方法可以将字符串日期拉到包,解析,如果值为null,我会设置最小日期。

I have now changed that so that it returns a null, or a parsed date...

我现在改变了它,以便返回null或解析日期......

    public static DateTime? ValueOrMin(string value)
    {
        if (string.IsNullOrWhiteSpace(value)) return null;
        return DateTime.Parse(value);
    }

Thanks.