Error Inserting Date RRS feed

  • Question

  • User325035487 posted

    Please find below my date insert code which was working ok!!! But suddenly it started inserting current date whenever the ContractDate in the form is left blank. Any help is appreciated

            DateTime? ContractDate = null;
            var ContractDated = Request["ContractDate"];
            if (Request["ContractDate"] != null)
                ContractDated = Request["ContractDate"] + " 00:00:00";
                ContractDate = DateTime.Parse(ContractDated, new CultureInfo("en-GB").DateTimeFormat);

    Edit: After playing around for sometime, I understand this, the if (Request["ContractDate"] != null) statement is not detecting the form field as empty. The statement inside the if loop is always executed, regardless if my form field is empty or has a jquery validated date. This is not a required form field item and should save as null in ms sql server 2012 database field of format datetime2

    This is my code for form field

    @Html.TextBox("ContractDate", Request["ContractDate"], new { @class = "date start form-control input-sm", size = "20" }) @Html.ValidationMessage("ContractDate")

    Sunday, June 26, 2016 7:33 PM


  • User-821857111 posted

    if (Request["ContractDate"] != null)



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 27, 2016 7:30 AM