This is a migrated thread and some comments may be shown as answers.

[Solved] DateTimePicker Grid Ajax Binding Issue

6 Answers 117 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
mtraner
Top achievements
Rank 1
mtraner asked on 14 Apr 2011, 10:12 PM
Okay, so here's the deal.  I have a Telerik Grid that when I click Edit will load a custom template.  The Grid code is here:

@(Html.Telerik().Grid<Autojockey.InventoryManagement.Website.Models.DealerGroup>()
    .Name("DealerGroups")
    .DataKeys(keys => keys.Add(d => d.DealerGroupId))
        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Image))
    .DataBinding(dataBinding =>
    {
        dataBinding.Ajax()
            .Select("IndexAjax", "DealerGroup").Enabled(true)
            .Insert("InsertAjax", "DealerGroup").Enabled(true)
            .Update("UpdateAjax", "DealerGroup").Enabled(true)
            .Delete("DeleteAjax", "DealerGroup").Enabled(true);
    })
    .Columns(columns =>
    {
        columns.Bound(d => d.Name);
        columns.Bound(d => d.City);
        columns.Bound(d => d.State);
        columns.Bound(d => d.ZipCode);
        columns.Bound(d => d.IsEnabled)
            .ClientTemplate("<input type='checkbox' disabled='disabled' name='isEnabledCheckbox' <#= IsEnabled? \"checked='checked'\" : \"\" #> />")
            .Title("Enabled")
            .HeaderHtmlAttributes(new { style = "text-align:center;" })
            .HtmlAttributes(new { style = "text-align:center;" });
        columns.Command(command => command.Delete()
            .ButtonType(GridButtonType.Image))
            .Title("Delete")
            .HeaderHtmlAttributes(new { style = "text-align:center" })
            .HtmlAttributes(new { style = "text-align:center;" });
        columns.Command(command => command.Edit()
            .ButtonType(GridButtonType.Image))
            .Title("Edit")
            .HeaderHtmlAttributes(new { style = "text-align:center" })
            .HtmlAttributes(new { style = "text-align:center;" });
    })
    .DetailView(details => details.ClientTemplate(
        Html.Telerik().TabStrip()
            .Name("TabStrip_<#= DealerGroupId #>")
            .SelectedIndex(0)
            .Items(items =>
            {
                items.Add().Text("Details").Content(
                    "<table>" +
                        // Name
                        "<tr>" +
                            "<td width='25%'><strong>Name</strong></td>" +
                            "<td width='75%'><i><#= Name #></i></td>" +
                        "</tr>" +
                        // Address1
                        "<tr>" +
                            "<td><strong>Address 1</strong></td>" +
                            "<td><i><#= Address1 #></i></td>" +
                        "</tr>" +
                        // Address2
                        "<tr>" +
                            "<td><strong>Address 2</strong></td>" +
                            "<td><i><#= Address2 #></i></td>" +
                        "</tr>" +
                        // City
                        "<tr>" +
                            "<td><strong>City</strong></td>" +
                            "<td><i><#= City #></i></td>" +
                        "</tr>" +
                        // State
                        "<tr>" +
                            "<td><strong>State</strong></td>" +
                            "<td><i><#= State #></i></td>" +
                        "</tr>" +
                        // Zipcode
                        "<tr>" +
                            "<td><strong>ZIP Code</strong></td>" +
                            "<td><i><#= ZipCode #></i></td>" +
                        "</tr>" +
                        // Contact
                        "<tr>" +
                            "<td><strong>Contact</strong></td>" +
                            "<td><i><#= ContactName #></i></td>" +
                        "</tr>" +
                        // Phone Number
                        "<tr>" +
                            "<td><strong>Phone</strong></td>" +
                            "<td><i><#= PhoneNumberFacade #></i></td>" +
                        "</tr>" +
                        // Email
                        "<tr>" +
                            "<td><strong>Email</strong></td>" +
                            "<td><i><a href='mailto:<#= Email #>'><#= Email #></a></i></td>" +
                        "</tr>" +
                        // Website 
                        "<tr>" +
                            "<td><strong>Website</strong></td>" +
                            "<td><i><a href='<#= Url #>' target='_blank'><#= Url #></a></i></td>" +
                        "</tr>" +
                    "</table>");
                items.Add().Text("Hours").Content(
                    "<table>" + 
                        "<tr>" + 
                            "<td><strong>Monday</strong</td>" + 
                            "<td><i><#= MondayHoursFacade #></i></td>" + 
                        "</tr>" +
                        "<tr>" +
                            "<td><strong>Tuesday</strong</td>" +
                            "<td><i><#= TuesdayHoursFacade #></i></td>" +
                        "</tr>" +
                        "<tr>" +
                            "<td><strong>Wednesday</strong</td>" +
                            "<td><i><#= WednesdayHoursFacade #></i></td>" +
                        "</tr>" +
                        "<tr>" +
                            "<td><strong>Thursday</strong</td>" +
                            "<td><i><#= ThursdayHoursFacade #></i></td>" +
                        "</tr>" +
                        "<tr>" +
                            "<td><strong>Friday</strong</td>" +
                            "<td><i><#= FridayHoursFacade #></i></td>" +
                        "</tr>" +
                        "<tr>" +
                            "<td><strong>Saturday</strong</td>" +
                            "<td><i><#= SaturdayHoursFacade #></i></td>" +
                        "</tr>" +
                        "<tr>" +
                            "<td><strong>Sunday</strong</td>" +
                            "<td><i><#= SundayHoursFacade #></i></td>" +
                        "</tr>" +
                    "</table>");
                items.Add().Text("Dealers").Content(
                    Html.Telerik().Grid<Autojockey.InventoryManagement.Website.Models.Dealer>()
                        .Name("Dealers_<#= DealerGroupId #>")
                        .DataKeys(keys => keys.Add(dealer => dealer.DealerId))
                        .Columns(columns =>
                        {
                            columns.Bound(d => d.Name);
                            columns.Bound(d => d.City);
                            columns.Bound(d => d.State);
                            columns.Bound(d => d.ZipCode);
                            columns.Bound(d => d.IsEnabled)
                                .ClientTemplate("<input type='checkbox' disabled='disabled' name='isEnabledCheckbox' <#= IsEnabled? \"checked='checked'\" : \"\" #> />")
                                .Title("Enabled")
                                .HeaderHtmlAttributes(new { style = "text-align:center;" })
                                .HtmlAttributes(new { style = "text-align:center;" });
                        })
                        .DataBinding(dataBinding =>
                            dataBinding.Ajax()
                                .Select("DealersForDealerGroupAjax", "Dealer", new { dealerGroupId = "<#= DealerGroupId #>" }).Enabled(true)
                            )
                        .ToHtmlString()
                );
            }).ToHtmlString()))
    .Sortable()
    .Groupable()
    .Editable(editing => editing.Mode(GridEditMode.PopUp))
    .Pageable(paging => paging.PageSize(15))
    .Filterable()
    .Footer(true))



The Template Control is here:
@model Autojockey.InventoryManagement.Website.Models.DealerGroup
<table class="Editor">
    <tr>
        <td align="right"><strong>@Html.LabelFor(model => model.Name)</strong></td>
        <td>
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </td>
    </tr>
    <tr>
        <td align="right"><strong>@Html.LabelFor(model => model.Address1)</strong></td>
        <td>
            @Html.EditorFor(model => model.Address1)
            @Html.ValidationMessageFor(model => model.Address1)
        </td>
    </tr>
    <tr>
        <td align="right"><strong>@Html.LabelFor(model => model.Address2)</strong></td>
        <td>
            @Html.EditorFor(model => model.Address2)
            @Html.ValidationMessageFor(model => model.Address2)
        </td>
    </tr>
    <tr>
        <td align="right"><strong>@Html.LabelFor(model => model.City)</strong></td>
        <td>
            @Html.EditorFor(model => model.City)
            @Html.ValidationMessageFor(model => model.City)
        </td>
    </tr>
    <tr>
        <td align="right"><strong>@Html.LabelFor(model => model.State)</strong></td>
        <td>
            @Html.EditorFor(model => model.State)
            @Html.ValidationMessageFor(model => model.State)
        </td>
    </tr>
    <tr>
        <td align="right"><strong>@Html.LabelFor(model => model.ZipCode)</strong></td>
        <td>
            @Html.EditorFor(model => model.ZipCode)
            @Html.ValidationMessageFor(model => model.ZipCode)
        </td>
    </tr>
    <tr>
        <td align="right"><strong>@Html.LabelFor(model => model.ContactName)</strong></td>
        <td>
            @Html.EditorFor(model => model.ContactName)
            @Html.ValidationMessageFor(model => model.ContactName)
        </td>
    </tr>
    <tr>
        <td align="right"><strong>@Html.LabelFor(model => model.PhoneNumber)</strong></td>
        <td>
            @Html.EditorFor(model => model.PhoneNumber)
            @Html.ValidationMessageFor(model => model.PhoneNumber)
        </td>
    </tr>
    <tr>
        <td align="right"><strong>@Html.LabelFor(model => model.Email)</strong></td>
        <td>
            @Html.EditorFor(model => model.Email)
            @Html.ValidationMessageFor(model => model.Email)
        </td>
    </tr>
    <tr>
        <td align="right"><strong>@Html.LabelFor(model => model.IsEnabled)</strong></td>
        <td>
            @Html.EditorFor(model => model.IsEnabled)
            @Html.ValidationMessageFor(model => model.IsEnabled)
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <table>
                <tr>
                    <th>Day</th><th>Open</th><th>Start</th><th>Close</th>
                </tr>
                <tr>
                    <td align="right"><strong>Mon</strong></td>
                    <td>
                        @Html.EditorFor(model => model.IsOpenMonday)
                        @Html.ValidationMessageFor(model => model.IsOpenMonday)
                    </td>
                    <td>
                        @Html.Telerik().TimePickerFor(model => model.MondayOpenTime).Effects(fx => fx.Expand().Opacity().OpenDuration(500).CloseDuration(500))
                        @Html.ValidationMessageFor(model => model.MondayOpenTime)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.MondayCloseTime)
                        @Html.ValidationMessageFor(model => model.MondayCloseTime)
                    </td>
                </tr>
                <tr>
                    <td align="right"><strong>Tue</strong></td>
                    <td>
                        @Html.EditorFor(model => model.IsOpenTuesday)
                        @Html.ValidationMessageFor(model => model.IsOpenTuesday)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.TuesdayOpenTime)
                        @Html.ValidationMessageFor(model => model.TuesdayOpenTime)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.TuesdayCloseTime)
                        @Html.ValidationMessageFor(model => model.TuesdayCloseTime)
                    </td>
                </tr>
                <tr>
                    <td align="right"><strong>Wed</strong></td>
                    <td>
                        @Html.EditorFor(model => model.IsOpenWednesday)
                        @Html.ValidationMessageFor(model => model.IsOpenWednesday)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.WednesdayOpenTime)
                        @Html.ValidationMessageFor(model => model.WednesdayOpenTime)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.WednesdayCloseTime)
                        @Html.ValidationMessageFor(model => model.WednesdayCloseTime)
                    </td>
                </tr>
                <tr>
                    <td align="right"><strong>Thu</strong></td>
                    <td>
                        @Html.EditorFor(model => model.IsOpenThursday)
                        @Html.ValidationMessageFor(model => model.IsOpenThursday)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.ThursdayOpenTime)
                        @Html.ValidationMessageFor(model => model.ThursdayOpenTime)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.ThursdayCloseTime)
                        @Html.ValidationMessageFor(model => model.ThursdayCloseTime)
                    </td>
                </tr>
                <tr>
                    <td align="right"><strong>Fri</strong></td>
                    <td>
                        @Html.EditorFor(model => model.IsOpenFriday)
                        @Html.ValidationMessageFor(model => model.IsOpenFriday)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.FridayOpenTime)
                        @Html.ValidationMessageFor(model => model.FridayOpenTime)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.FridayCloseTime)
                        @Html.ValidationMessageFor(model => model.FridayCloseTime)
                    </td>
                </tr>
                <tr>
                    <td align="right"><strong>Sat</strong></td>
                    <td>
                        @Html.EditorFor(model => model.IsOpenSaturday)
                        @Html.ValidationMessageFor(model => model.IsOpenSaturday)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.SaturdayOpenTime)
                        @Html.ValidationMessageFor(model => model.SaturdayOpenTime)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.SaturdayCloseTime)
                        @Html.ValidationMessageFor(model => model.SaturdayCloseTime)
                    </td>
                </tr>
                <tr>
                    <td align="right"><strong>Sun</strong></td>
                    <td>
                        @Html.EditorFor(model => model.IsOpenSunday)
                        @Html.ValidationMessageFor(model => model.IsOpenSunday)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.SundayOpenTime)
                        @Html.ValidationMessageFor(model => model.SundayOpenTime)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.SundayCloseTime)
                        @Html.ValidationMessageFor(model => model.SundayCloseTime)
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>


The model is here:
#region Usings


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using System.Xml.Serialization;


#endregion


namespace Autojockey.InventoryManagement.Website.Models
{
    [Bind(Exclude = "DealerGroupId")]
    public class DealerGroup
    {
        [Key]
        [ScaffoldColumn(false)]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public Guid DealerGroupId { get; set; }


        [Required]
        [StringLength(50, ErrorMessage = "Maximum length is 50 characters")]
        public string Name { get; set; }


        [DisplayName("Address 1")]
        [StringLength(50, ErrorMessage = "Maximum length is 50 characters")]
        public string Address1 { get; set; }
        
        [DisplayName("Address 2")]
        [StringLength(50, ErrorMessage = "Maximum length is 50 characters")]
        public string Address2 { get; set; }


        [StringLength(50, ErrorMessage = "Maximum length is 50 characters")]
        public string City { get; set; }


        [StringLength(2, ErrorMessage = "Maximum length is 2 characters")]
        public string State { get; set; }


        [DisplayName("ZIP Code")]
        [StringLength(5, ErrorMessage = "Maximum length is 5 characters")]
        public string ZipCode { get; set; }


        [DisplayName("Contact")]
        [StringLength(50, ErrorMessage = "Maximum length is 50 characters")]
        public string ContactName { get; set; }
        
        [DisplayName("Phone Number")]
        [DataType(DataType.PhoneNumber)]
        [StringLength(10, ErrorMessage = "Maximum length is 10 characters")]
        public string PhoneNumber { get; set; }
        
        [DisplayName("Email")]
        [DataType(DataType.EmailAddress)]
        [StringLength(256, ErrorMessage = "Maximum length is 256 characters")]
        public string Email { get; set; }
        
        [DisplayName("SMS Opt-In")]
        public bool IsSmsOptIn { get; set; }
        
        [DisplayName("Email Opt-In")]
        public bool IsEmailOptIn { get; set; }
        
        [DisplayName("Website")]
        [DataType(DataType.Url)]
        [StringLength(256, ErrorMessage = "Maximum length is 256 characters")]
        public string Url { get; set; }
        
        [DisplayName("Open Monday")]
        public bool IsOpenMonday { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Monday Start Time")]
        public DateTime? MondayOpenTime { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Monday Close Time")]
        public DateTime? MondayCloseTime { get; set; }


        [DisplayName("Open Tuesday")]
        public bool IsOpenTuesday { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Tuesday Start Time")]
        public DateTime? TuesdayOpenTime { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Tuesday Close Time")]
        public DateTime? TuesdayCloseTime { get; set; }
        
        [DisplayName("Open Wednesday")]
        public bool IsOpenWednesday { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Wednesday Start Time")]
        public DateTime? WednesdayOpenTime { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Wednesday Close Time")]
        public DateTime? WednesdayCloseTime { get; set; }
        
        [DisplayName("Open Thursday")]
        public bool IsOpenThursday { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Thursday Start Time")]
        public DateTime? ThursdayOpenTime { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Thursday Close Time")]
        public DateTime? ThursdayCloseTime { get; set; }
        
        [DisplayName("Open Friday")]
        public bool IsOpenFriday { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Friday Start Time")]
        public DateTime? FridayOpenTime { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Friday Close Time")]
        public DateTime? FridayCloseTime { get; set; }
        
        [DisplayName("Open Saturday")]
        public bool IsOpenSaturday { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Saturday Start Time")]
        public DateTime? SaturdayOpenTime { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Saturday Close Time")]
        public DateTime? SaturdayCloseTime { get; set; }
        
        [DisplayName("Open Sunday")]
        public bool IsOpenSunday { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Sunday Start Time")]
        public DateTime? SundayOpenTime { get; set; }


        [DataType(DataType.Time)]
        [DisplayName("Sunday Close Time")]
        public DateTime? SundayCloseTime { get; set; }


        [DisplayName("Enabled")]
        public bool IsEnabled { get; set; }


        [ScaffoldColumn(false)]
        public bool IsDeleted { get; set; }


        [ScaffoldColumn(false)]
        public DateTime CreatedDate { get; set; }


        [ScaffoldColumn(false)]
        public DateTime LastModified { get; set; }


        [ScaffoldColumn(false)]
        public string CreatedBy { get; set; }


        [ScaffoldColumn(false)]
        public string ModifiedBy { get; set; }
}
}

Here is my controller:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Autojockey.InventoryManagement.Website.Models;
using Telerik.Web.Mvc;


namespace Autojockey.InventoryManagement.Website.Controllers
{
    public class DealerGroupController : Controller
    {
        #region Database Access
        private readonly InventoryManagementEntities _inventoryManagementDb = new InventoryManagementEntities();


        private IEnumerable<DealerGroup> GetAllDealerGroups()
        {
            var dealerGroups = _inventoryManagementDb.DealerGroups
                .Where(dg => !dg.IsDeleted)
                .OrderBy(dg => dg.Name)
                .ToList();
            return dealerGroups;
        }
        #endregion


        [Authorize(Roles = MvcApplication.SYSTEM_ADMINISTRATOR)]
        public ActionResult Index()
        {
            var dealerGroups = GetAllDealerGroups();
            return View(dealerGroups);
        }


        [Authorize(Roles = MvcApplication.SYSTEM_ADMINISTRATOR)]
        [GridAction]
        public ActionResult IndexAjax()
        {
            var dealerGroups = GetAllDealerGroups();
            // ReSharper disable Asp.NotResolved
            return View(new GridModel(dealerGroups));
            // ReSharper restore Asp.NotResolved
        }


        [Authorize(Roles = MvcApplication.SYSTEM_ADMINISTRATOR)]
        [GridAction]
        public ActionResult InsertAjax()
        {
            var dealerGroup = new DealerGroup();
            if (TryUpdateModel(dealerGroup))
            {
                var user = Membership.GetUser();
                var timeStamp = DateTime.UtcNow;
                dealerGroup.CreatedDate = timeStamp;
                dealerGroup.CreatedBy = user.UserName;
                dealerGroup.LastModified = timeStamp;
                dealerGroup.ModifiedBy = user.UserName;
                dealerGroup.IsDeleted = false;


                //if (!dealerGroup.IsOpenMonday)
                //{
                //    dealerGroup.MondayOpenTime = null;
                //    dealerGroup.MondayCloseTime = null;
                //}
                //if (!dealerGroup.IsOpenTuesday)
                //{
                //    dealerGroup.TuesdayOpenTime = null;
                //    dealerGroup.TuesdayCloseTime = null;
                //}
                //if (!dealerGroup.IsOpenWednesday)
                //{
                //    dealerGroup.WednesdayOpenTime = null;
                //    dealerGroup.WednesdayCloseTime = null;
                //}
                //if (!dealerGroup.IsOpenThursday)
                //{
                //    dealerGroup.ThursdayOpenTime = null;
                //    dealerGroup.ThursdayCloseTime = null;
                //}
                //if (!dealerGroup.IsOpenFriday)
                //{
                //    dealerGroup.FridayOpenTime = null;
                //    dealerGroup.FridayCloseTime = null;
                //}
                //if (!dealerGroup.IsOpenSaturday)
                //{
                //    dealerGroup.SaturdayOpenTime = null;
                //    dealerGroup.SaturdayCloseTime = null;
                //}
                //if (!dealerGroup.IsOpenSunday)
                //{
                //    dealerGroup.SundayOpenTime = null;
                //    dealerGroup.SundayCloseTime = null;
                //}
                _inventoryManagementDb.DealerGroups.Add(dealerGroup);
                _inventoryManagementDb.SaveChanges();
            }
            
            var dealerGroups = GetAllDealerGroups();
            // ReSharper disable Asp.NotResolved
            return View(new GridModel(dealerGroups));
            // ReSharper restore Asp.NotResolved
        }


        [Authorize(Roles = MvcApplication.SYSTEM_ADMINISTRATOR)]
        [GridAction]
        public ActionResult UpdateAjax(Guid id)
        {
            var dealerGroup = _inventoryManagementDb.DealerGroups.Find(id);
            if (dealerGroup.MondayOpenTime == null)
                dealerGroup.MondayOpenTime = DateTime.Now;
            TryUpdateModel(dealerGroup);


            var user = Membership.GetUser();
            dealerGroup.LastModified = DateTime.UtcNow;
            dealerGroup.ModifiedBy = user.UserName;


            //if (!dealerGroup.IsOpenMonday)
            //{
            //    dealerGroup.MondayOpenTime = null;
            //    dealerGroup.MondayCloseTime = null;
            //}
            //if (!dealerGroup.IsOpenTuesday)
            //{
            //    dealerGroup.TuesdayOpenTime = null;
            //    dealerGroup.TuesdayCloseTime = null;
            //}
            //if (!dealerGroup.IsOpenWednesday)
            //{
            //    dealerGroup.WednesdayOpenTime = null;
            //    dealerGroup.WednesdayCloseTime = null;
            //}
            //if (!dealerGroup.IsOpenThursday)
            //{
            //    dealerGroup.ThursdayOpenTime = null;
            //    dealerGroup.ThursdayCloseTime = null;
            //}
            //if (!dealerGroup.IsOpenFriday)
            //{
            //    dealerGroup.FridayOpenTime = null;
            //    dealerGroup.FridayCloseTime = null;
            //}
            //if (!dealerGroup.IsOpenSaturday)
            //{
            //    dealerGroup.SaturdayOpenTime = null;
            //    dealerGroup.SaturdayCloseTime = null;
            //}
            //if (!dealerGroup.IsOpenSunday)
            //{
            //    dealerGroup.SundayOpenTime = null;
            //    dealerGroup.SundayCloseTime = null;
            //}
            _inventoryManagementDb.SaveChanges();
            
            var dealerGroups = GetAllDealerGroups();
            // ReSharper disable Asp.NotResolved
            return View(new GridModel(dealerGroups));
            // ReSharper restore Asp.NotResolved
        }


        [Authorize(Roles = MvcApplication.SYSTEM_ADMINISTRATOR)]
        [GridAction]
        public ActionResult DeleteAjax(Guid id)
        {
            var dealerGroup = _inventoryManagementDb.DealerGroups.Find(id);
            dealerGroup.IsDeleted = true;
            dealerGroup.IsEnabled = false;
            _inventoryManagementDb.SaveChanges();


            var dealerGroups = GetAllDealerGroups();
            // ReSharper disable Asp.NotResolved
            return View(new GridModel(dealerGroups));
            // ReSharper restore Asp.NotResolved
        }


        #region Utility Methods
        [Authorize(Roles = MvcApplication.SYSTEM_ADMINISTRATOR)]
        public ActionResult Export()
        {
            throw new NotImplementedException();
        }
        #endregion
    }
}


The problem is, that when I click the Edit button for a row in the grid, the form pops up, but the Time pickers. show the full date / time, not just the time (see edit_pre-click.png); however, it is the correct value from the database.  If I click anywhere in the browser, the time pickers change to show only the time; however, it is the wrong time for all fields.  They reset to 4:00, but retain the original values am / pm settings.  See the second image (edit-postclick.png).  The only difference was a mouse click in a blank section of the browser.

6 Answers, 1 is accepted

Sort by
0
mtraner
Top achievements
Rank 1
answered on 14 Apr 2011, 10:14 PM
I also meant to say that if the save button is clicked, it will save the 4:00 values in the db.
0
mtraner
Top achievements
Rank 1
answered on 14 Apr 2011, 10:14 PM
Also, this is MVC3 v.2011.1.414.340
0
Rosen
Telerik team
answered on 15 Apr 2011, 09:55 AM
Hello mtraner,

I was able to recreate the issue you have described. However, I'm happy to inform you that we have managed to address it and I have attached a modified version of grid.editing.js file. Please, replace your project's version of the file with  the attached one. I have updated your telerik points too.

Regards,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
mtraner
Top achievements
Rank 1
answered on 15 Apr 2011, 01:33 PM
Thank you for the reply.  That definitely corrected the mouseclick issue causing the full date time to show when the control was only supposed to show time; however, I still have the issue where the times are displayed as 4:00.  It retains the am / pm setting, but displays 4:00 for every time regardless of what the time is in the database.  
0
mtraner
Top achievements
Rank 1
answered on 15 Apr 2011, 02:43 PM
Here is a screenshot showing the value in the grid (meaning it's saved properly to the db), and then values that populate when the Edit button is clicked.  If you notice, the AM / PM for each corresponding time is correct, but the times all are set to 4:00.  If I click the save button it does change all the times in the db to what is incorrectly populated in the edit form.
0
mtraner
Top achievements
Rank 1
answered on 15 Apr 2011, 04:05 PM
Okay, A bit more information on this.  It seems to be an issue with the Time Picker using the month as the hour.  That's why it sets it to 4.  If I change the Data type attribute on my model class to DateTime instead of time (causing the EditorFor to use a DateTimePicker instead of just a Time picker), it shows the correct value.

[DataType(DataType.Time)]
[DisplayName("Monday Start Time")]
public DateTime? MondayOpenTime { get; set; }
 
[DataType(DataType.Time)]
[DisplayName("Monday Close Time")]
public DateTime? MondayCloseTime { get; set; }

If I have it set that way, it looks like incorrect as in the image TimePicker.png below.

If I set it as below, then it looks correct as in the image DateTimePicker.png below.
[DataType(DataType.DateTime)]
[DisplayName("Monday Start Time")]
public DateTime? MondayOpenTime { get; set; }
  
[DataType(DataType.DateTime)]
[DisplayName("Monday Close Time")]
public DateTime? MondayCloseTime { get; set; }

I tested this by setting the date on one of those datetime fields to september, and in the time picker it shows as 9:00 instead of 4:00.
Tags
Date/Time Pickers
Asked by
mtraner
Top achievements
Rank 1
Answers by
mtraner
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or