I am getting value XX is not valid. But I am binding the correct datatype to the Model and I am still getting this error. Please find the error in enter image description here. My controller is considering all datatype besides string to be not valid. Even the StartData and EndDate is throwing the same exception though I am binding the correct datatype.

I am not sure am I missing anything here. The worse part here is if I try to implement same (file) in another sample project it is working fine.

Following is my Model

public class Dept_User_Link
    {
        public Dept_User_Link()
        {
            StartDate = DateTime.Now;
            EndDate = DateTime.Now;
        }

        private List<Dept_User_Link> deptUserLink = new List<Dept_User_Link>();
        public int ID { get; set; }
        [Required]
        public int DeptID { get; set; }
        [Required]
        public int UserID { get; set; }
        [Required]
        public Guid Dummy { get; set; }
        [Required]
        public DateTime StartDate { get; set; }
        [Required]
        [DateRange(StartDateEditFieldName = "StartDate")]
        public DateTime EndDate { get; set; }

}

and following is my controller

      public ActionResult GridVwPartial()
            {
                var model = new Dept_User_Link().GetDeptUsersLink();
                ViewData["Departments"] = new Department().GetDepartments().Select(x => new { DeptID = x.ID, Name = x.Name }).ToList();
                ViewData["Users"] = new Users().GetUsers().Select(x => new { UserID = x.ID, Name = x.Name }).ToList();
                ViewData["GuidVals"] = new GuidVal().GuidValData();
                return PartialView("GridVwPartial", model);
            }

  public ActionResult AddNew(Dept_User_Link data) {
            // Add 'data' values to the underlying datasource
            // ...

            var model = new Dept_User_Link().GetDeptUsersLink();
            ViewData["Departments"] = new Department().GetDepartments().Select(x => new { DeptID = x.ID, Name = x.Name }).ToList();
            ViewData["Users"] = new Users().GetUsers().Select(x => new { UserID = x.ID, Name = x.Name }).ToList();

            return GridVwPartial();
        }

and following is my View

@using ROCKtree.CCTVWeb.Models
@model IList<Dept_User_Link>
@{


    Html.DevExpress().GridView<Dept_User_Link>(settings =>
    {
        settings.Name = "cascadingExample";
        settings.CallbackRouteValues = new { Controller = "Grid", Action = "GridVwPartial" };
        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Grid", Action = "AddNew" };
        settings.CommandColumn.Visible = true;
        settings.CommandColumn.ShowNewButtonInHeader = true;
        settings.SettingsEditing.Mode = GridViewEditingMode.EditForm;
        settings.KeyFieldName = "ID";

        settings.Columns.Add(m => m.DeptID, column =>
        {
            column.EditorProperties().ComboBox(x =>
            {
                x.TextField = "Name";
                x.ValueField = "DeptID";
                x.DataSource = ViewData["Departments"];
                x.ClientSideEvents.SelectedIndexChanged = "OnSelectedDeptChanges";
                x.ValidationSettings.CausesValidation = true;
                //x.ClientSideEvents.SelectedIndexChanged = "";
            });
        });

        settings.Columns.Add(m => m.UserID, column =>
        {
            column.EditorProperties().ComboBox(x =>
            {
                x.TextField = "Name";
                x.ValueField = "UserID";
                //x.DataSource = ViewData["Users"];
                x.LoadDropDownOnDemand = true;
                x.CallbackRouteValues = new { Controller = "Grid", Action = "UserCallback" };
                x.ClientSideEvents.BeginCallback = "UserComboBox_BeginCallback";
                // x.ClientSideEvents.SelectedIndexChanged = "";

            });

        });

        settings.Columns.Add(m => m.Dummy, column =>
        {
            column.EditorProperties().ComboBox(cmb =>
            {
                cmb.TextField = "Name";
                cmb.ValueField = "ID";
                cmb.DataSource = ViewData["GuidVals"];
            });
        });


        settings.Columns.Add(m => m.StartDate, column =>
        {
            column.EditorProperties().DateEdit(clm =>
            {
                clm.TimeSectionProperties.Visible = true;
                clm.DisplayFormatString = "dd-MMM-yy HH:mm";
                clm.DisplayFormatInEditMode = true;
                clm.TimeSectionProperties.TimeEditProperties.EditFormatString = "HH";
                clm.TimeSectionProperties.TimeEditProperties.EditFormat = EditFormat.Custom;
                clm.UseMaskBehavior = true;
                clm.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithTooltip;
                clm.ValidationSettings.Display = Display.Dynamic;
                clm.ValidationSettings.CausesValidation = true;
                clm.ValidationSettings.SetFocusOnError = true;
            });
            //column.SetEditItemTemplateContent(c =>
            //{
            //    ViewContext.Writer.Write("<div class='form-group'><div class='input-group date' id='datetimepicker1'><input type='text' class=\"form-control\" /><span class=\"input-group-addon\">");
            //    ViewContext.Writer.Write("<span class=\"glyphicon glyphicon-calendar\"></span></span></div></div>");
            //});
        });


        settings.Columns.Add(m => m.EndDate, column =>
        {
            column.EditorProperties().DateEdit(clm =>
            {
                clm.TimeSectionProperties.Visible = true;
                clm.DisplayFormatString = "dd-MMM-yy HH:mm";
                clm.DisplayFormatInEditMode = true;
                clm.TimeSectionProperties.TimeEditProperties.EditFormatString = "HH";
                clm.TimeSectionProperties.TimeEditProperties.EditFormat = EditFormat.Custom;
                clm.UseMaskBehavior = true;
                clm.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithTooltip;
                clm.ValidationSettings.Display = Display.Dynamic;
                clm.ValidationSettings.CausesValidation = true;
                clm.ValidationSettings.SetFocusOnError = true;
            });
            //column.SetEditItemTemplateContent(c =>
            //{
            //    ViewContext.Writer.Write("<div class='form-group'><div class='input-group date' id='datetimepicker1'><input type='text' class=\"form-control\" /><span class=\"input-group-addon\">");
            //    ViewContext.Writer.Write("<span class=\"glyphicon glyphicon-calendar\"></span></span></div></div>");
            //});
        });
    }).Bind(Model).GetHtml();
}

Data for the Dummy Property

   public IList<GuidVal> GuidValData()
            {
                if (guidVal == null || guidVal.Count() == 0)
                {
                    //List<Department> deptList = new List<Department>();
                    List<string> deptValues = File.ReadLines(path).ToList();

                    foreach (string data in deptValues)
                    {
                        if (!string.IsNullOrEmpty(data))
                        {
                            string[] str = data.Split(separators, StringSplitOptions.None);
                            GuidVal deptLnk = new GuidVal();
                            deptLnk.ID = Guid.Parse(str[0]);
                            deptLnk.Name = str[1];
                            this.guidVal.Add(deptLnk);
                        }
                    }
                }
                return guidVal;

            }
0

There are 0 answers