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

[Solved] error using date template on ajax editing

2 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marco
Top achievements
Rank 1
Marco asked on 05 Mar 2010, 02:37 PM
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




  

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 05 Mar 2010, 03:37 PM
Hello Marco,

Unfortunately the provided code does not indicate the reason for this exception. Could you provide a working example which shows the problem? You can send it to atanas.korchev at telerik.com.

Regards,
Atanas Korchev
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
Marco
Top achievements
Rank 1
answered on 05 Mar 2010, 03:40 PM
ok Atanas i will try to replicate this behavior in a demo project and that i will send you.

many thanks


Tags
Grid
Asked by
Marco
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Marco
Top achievements
Rank 1
Share this question
or