This question is locked. New answers and comments are not allowed.
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()));
}
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()));
}