locked
auto validation error RRS feed

  • Question

  • User81789783 posted

    i m working in EF 6 and MVC 5

    i find below error  highlighted in red ,though i did not specified any where in application. let me share view model and db script and other piece of code

    The field HoldiayDate must be a date.

    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated from a template.
    //
    //     Manual changes to this file may cause unexpected behavior in your application.
    //     Manual changes to this file will be overwritten if the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------
    
    namespace CallCenterCRM
    {
        using System;
        using System.Collections.Generic;
        
        public partial class TBL_Holiday
        {
            public int HolidayId { get; set; }
            public Nullable<System.DateTime> HoldiayDate { get; set; }
            public string ReasonforHoliday { get; set; }
            public Nullable<int> Empscrutinize { get; set; }
        }
    }
    
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Web.Mvc;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System;
    using System.Web.Mvc;
    using System.Collections.Generic;
    using System.Linq;
    using System.ComponentModel.DataAnnotations;
    using System.Web;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Web.Mvc;
    
    namespace CallCenterCRM.Models
    {
        public class EmpHolidayViewModel
        {
            [HiddenInput(DisplayValue = true)]
            [Key]
            public int HolidayId { get; set; }
            public System.DateTime ? HoldiayDate { get; set; }
            public string ReasonforHoliday { get; set; }
    
            public int ? Empscrutinize { get; set; }
    
           // public String SelectedEmployee { get; set; }
            public IEnumerable<SelectListItem> Employees { get; set; }
    
    
        }
    }
    @model CallCenterCRM.Models.EmpHolidayViewModel
    <script type="text/javascript">
    	$(function(){
    	    $("#HoldiayDate").datepicker({
    			changeMonth: true,
    			changeYear: true,
    			dateFormat: 'dd.mm.yy'
    
    		});
    	});
    </script>
    @using (Html.BeginForm()) 
    {
        @Html.AntiForgeryToken()
        
        <div class="form-horizontal">
            <h4>EmpHolidayViewModel</h4>
            <hr />
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="form-group">
                @Html.LabelFor(model => model.HoldiayDate, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.HoldiayDate, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.HoldiayDate, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.ReasonforHoliday, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.ReasonforHoliday, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.ReasonforHoliday, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.Empscrutinize, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownListFor(model => Model.Empscrutinize, new SelectList(Model.Employees, "Value", "Text"), "..Select..", htmlAttributes: new { @class = "form-control", id = "Employee" })
    
    
                    @Html.ValidationMessageFor(model => model.Employees, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="Create" class="btn btn-default" />
                </div>
            </div>
        </div>
    }
    
    <div>
        @Html.ActionLink("Back to List", "Index")
    </div>
    

    USE [CallCenter]
    GO

    /****** Object: Table [dbo].[TBL_Holiday] Script Date: 02/15/2018 17:00:45 ******/
    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    SET ANSI_PADDING ON
    GO

    CREATE TABLE [dbo].[TBL_Holiday](
    [HolidayId] [int] IDENTITY(1,1) NOT NULL,
    [HoldiayDate] [datetime] NULL,
    [ReasonforHoliday] [varchar](50) NULL,
    [Empscrutinize] [int] NULL,
    CONSTRAINT [PK_TBL_Holiday] PRIMARY KEY CLUSTERED
    (
    [HolidayId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF
    GO

    Thursday, February 15, 2018 12:00 PM

All replies

  • User475983607 posted

    Looks like a model validation error due to an invalid (custom) date format; mm.dd.yy.  Set a breakpoint and debug the code.

    Thursday, February 15, 2018 2:48 PM
  • User1400794712 posted

    Hi erum,

    Just like what mgebhard said, it's 'dateFormat: 'dd.mm.yy''  causes this problem.

    'dd.mm.yy' is not a valid datetime format. Please modify it to:

    dateFormat: 'dd/mm/yy'
    

    Best Regards,

    Daisy

    Saturday, February 24, 2018 9:40 AM