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

[Solved] Changes to DateTimePicker Editor Don't Appear In Controller

5 Answers 107 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.
Abigail
Top achievements
Rank 1
Abigail asked on 31 Mar 2011, 08:53 PM
ASP.NET MVC 2
OS: Windows
Browser: Firefox 3.6.16
Telerik: Extensions for ASP.NET MVC Q1 2011
Preferred Language: C#

I am using a DateTimePicker in an Editor Template for a grid with Ajax binding.

When I edit the DateTime value and the values are passed to my controller object, I always receive the original value that my DateTimePicker was set to. The updates I make in the editor never stick, and aren't passed to the controller. So I can never update the DateTime column.

All of the other editor templates I use, including dropdown lists and a DatePicker, work perfectly.

The name attribute of the DateTimePicker HTML element is the same as the proterty name of the bound column.


**DateTime.ascx**

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime?>" %>
<%= Html.Telerik().DateTimePicker()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .Value(Model > DateTime.MinValue ? Model : DateTime.Now)
%>

**AdminModels.cs**

public class ClusterSystemModel
{

    [DataType(DataType.DateTime), Required]
    public DateTime? DateActive { get; set; }
    [DataType(DataType.DateTime), Required]
    public DateTime? DateInactive { get; set; }

    [DisplayName("Id")]
    [UIHint("IdField")]
    public string SystemId { get; set; }

    [UIHint("ReadOnlyField")]
    [ReadOnly(true)]
    public string Platform { get; set; }

    [Required]
    public string Name { get; set; }

    [UIHint("SystemTypes")]
    public string SystemType { get; set; }
    [UIHint("SystemStatuses")]
    public string SystemStatus { get; set; }

    public ClusterSystemModel() { }

    public ClusterSystemModel(M5TrustEntities.VwSystemsWithPlatform system)
    {
        SystemId = system.Id.ToString();
        Name = system.Name;
        SystemType = system.SystemTypeName;
        SystemStatus = system.SystemStatusName;
        Platform = system.PlatformName;
        DateActive = (DateTime)system.DateActive;
        if (system.DateInactive != null)
            DateInactive = (DateTime)system.DateInactive;
    }

}

**TrustAdminController.cs**

[AcceptVerbs(HttpVerbs.Post)]
[GridAction]
public ActionResult _UpdateSystem(string id, DateTime DateActive, FormCollection collection)
{
    var newSystem = new ClusterSystemModel { SystemId = id };

    using (M5trust_Entities m5 = new M5trust_Entities())
        if (TryUpdateModel(newSystem))
            SystemRepository.UpdateSystem(newSystem, m5);

    return View(new GridModel(GetSystemList()));
}

5 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 01 Apr 2011, 09:20 AM
Hello Abigail,

 
This is a known issue, which I am glad to inform you is already fixed. The fix will be included in the next official release of Telerik components for ASP.NET MVC. Check this thread.

Greetings,
Georgi Krustev
the Telerik team
0
Abigail
Top achievements
Rank 1
answered on 01 Apr 2011, 03:23 PM
Hey! Thank you for your response, but I've updated to the latest Telerik release and tried replacing the javascript file included in that other forum, but it still doesn't work.

It's strange, because the DatePicker object works perfectly, passing in information normally to the controller, but both the TimePicker and the DateTimePicker fail to update correctly. Do you have any idea what else might be going wrong for me?
0
Georgi Krustev
Telerik team
answered on 04 Apr 2011, 09:57 AM
Hello Abigail,

 
The described issue was fixed in the JavaScript file attached in the aforementioned forum thread. If this does not fix the problem I will suggest you to send us a test project which reproduces this issue.

All the best,
Georgi Krustev
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
Abigail
Top achievements
Rank 1
answered on 04 Apr 2011, 02:47 PM
That's a very good suggestion. Thank you for your help.
0
Neil
Top achievements
Rank 1
answered on 17 Jun 2011, 07:15 PM
I'm seeing very similar behavior.  We are using version 2011.1.315.235 in an .net MVC2 application.  The datepicker is in the default popup (I haven't created an editor template).  The popup shows the current date/time but the controller shows the values passed in as being 1/1/0001.  All other text fields in the popup are being passed correctly to the controller.  I noticed our application has two EditorTemplates folders - one under the root and one under the Shared folder (don't know if this makes a difference - just mentioning it.)  I'm certain the Shared\EditorTemplates folder is the one being called so I excluded the other.  Both folders have slightly different versions of the date picker - one has the .HtmlAttributes property (.HtmlAttributes(new { id = ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty) + "_wrapper" })), one doesn't.  I tried both using the attribute and not with no differential effect.  The only way i could get the date to be passed in was to rename the Date.ascx file to Date_x.ascx so Telerik couldn't find it.  Didn't seem like the best solution to me (why am i paying for a license for software I'm not using!)

Can you help?

Addendum...

I found a forum post that discussed a similar issue.  that post had a zip file with a new .js file that seemed to have solved my problem.  That post is located here: http://www.telerik.com/community/forums/aspnet-mvc/datepicker/date-time-picker-does-not-work-in-grid-mvc2-2011-1-315.aspx in case someone else with this problem stumbles on this post first.

Tags
Date/Time Pickers
Asked by
Abigail
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Abigail
Top achievements
Rank 1
Neil
Top achievements
Rank 1
Share this question
or