This question is locked. New answers and comments are not allowed.
hello community, i was wondering if someone have the same error i have using the editor template for dates in ajax binding and editing.
System.InvalidCastException: not possible to associate object type 'System.Collections.Generic.List`1[My DTO]' to type 'System.IConvertible'.
this is my configuration:
DTO:
| namespace SIG.DomainModel.Entities |
| { |
| [MetadataType(typeof(EmentaMetadata))] |
| public partial class Ementa |
| { |
| } |
| public class EmentaMetadata |
| { |
| // Date Time property that is related to error and attribute to call editor template |
| [DataType(DataType.Date)] |
| public DataType data { get; set; } |
| } |
| } |
controller action:
| [GridAction] |
| public ActionResult Create() |
| { //this returns a GridModel<DTO> |
| return View(ServiceLocator.Current.GetInstance<IEmentas>().GetAvailableEmentas()); |
| } |
view
| <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<GridModel<Ementa>>" %> |
| <%@ Import Namespace="SIG.DomainModel.Entities" %> |
| <%@ Import Namespace="Telerik.Web.Mvc" %> |
| <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> |
| <div id="menucontainer"> |
| <% Html.Telerik().Grid(Model.Data) |
| .Name("Grid") |
| .Toolbar(commands => commands.Insert()) |
| .Toolbar(commands => commands.Custom().Text("Copy").Url("javascript:copyRow()")) |
| .DataKeys(dataKeys => dataKeys.Add(o => o.id)) |
| .Columns(columns => |
| { |
| columns.Bound(o => o.idUnidade).Title("Unidade(s)"); |
| columns.Bound(o => o.descricao); |
| columns.Bound(o => o.data); // this is the property for date editor template that returns the error |
| columns.Bound(o => o.idRefeicao); |
| columns.Bound(o => o.id).Format(Html.ActionLink(" ", "EmentasPratos", new { idEmenta = "{0}" }, new { @class = "iconDetail" }).ToString()).Encoded(false).Title("Pratos").Width(10); ; |
| columns.Command(commands => commands.Edit()); |
| }) |
| .DataBinding(dataBinding => dataBinding |
| .Ajax() |
| .Update("Update", "Ementas") |
| .Select("Create", "Ementas") |
| .Insert("Insert", "Ementas")) |
| .Pageable() |
| .Sortable() |
| .Filterable() |
| .Selectable() |
| .Render(); |
| %> |
| </div> |
| <script type="text/javascript"> |
| function copyRow() { |
| var $grid = $('#Grid'); |
| var grid = $grid.data('tGrid'); |
| var $selectedRow = $('#Grid').find('tr.t-state-selected'); |
| if ($selectedRow.length) { |
| (grid.addRow || grid.createRow).apply(grid); |
| $selectedRow.find('td').each(function(i) { |
| $grid.find('.t-edit-form tr td') |
| .eq(i) |
| .find('input,select') |
| .val($(this).text()); |
| }); |
| } |
| } |
| </script> |
| </asp:Content> |
and finally the editor:
| <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime>" %> |
| <%= Html.Telerik().DatePicker() |
| .Name(ViewData.TemplateInfo.HtmlFieldPrefix) |
| .HtmlAttributes(new { id = ViewData.TemplateInfo.HtmlFieldPrefix + DateTime.Now.Millisecond.ToString(), |
| name = ViewData.TemplateInfo.HtmlFieldPrefix |
| }) |
| .Value(Model > DateTime.MinValue? Model : DateTime.Today) |
| %> |
Someone knows what can be wrong? it works if i pass to server binding
best regards