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

Kendo Grid throwing exception when trying to add toolbar and/or command columns

1 Answer 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 07 Jun 2013, 09:20 PM
Hi Below is my code :

The issue is when I try to add the sections marked as bold I get this exception  The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'System.String'.

Note : I have a single controller that serves multiple views from multiple controller.


@model IEnumerable<mobiCore.Models.ChecklistApprovalModel>
@{
    ViewBag.Title = "EditApprovals";
 
    }
<h2>Approvals</h2>
 
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
 
 
<style type="text/css">
.detail-title-field{
    width:98%;
    float:left;
    margin:0px 5px;
}
 
.detail-value-field{
    width:98%;
    min-height:1.2em !important;
    background-color: #E3E4FA;
    margin:5px;
    padding:0 2px 0 2px;
    border:1px solid  #728FCE;
    display:block;
    float:left;
}
</style>
 
<div id="generatetsDiv" style="width: 100%;">
 
        
@using (Html.BeginForm("index_approvals", "Checklist"))
{
  
          @(Html.Kendo().Grid(Model)
            .Name("ChecklistGrid")
          .Columns(columns => {
              columns.Bound(p1 => p1.ApprovalID).Title("ApprovalID").Width(10);
              columns.Bound(p1 => p1.ManagerApproval).Title("IsApproved").Width(10);
              columns.Bound(p1 => p1.SubmitterID).Title("SubmitterID").Width(10);
              columns.Bound(p1 => p1.ApproverID).Title("ApproverID").Width(10);
              columns.ForeignKey(p1 => p1.ChecklistItemDateID,
                    (System.Collections.IEnumerable)ViewData["checklistitemdatecoll"],
                    "ChecklistItemDateID", "DateValue").Title("ChecklistDate").Width(50);})
                     
            .ToolBar(toolbar => toolbar.Save())
            //.Editable(editable =>editable.Mode(GridEditMode.InCell))
            .Selectable(select => select.Mode(GridSelectionMode.Single))
            .Pageable()
            .Sortable()
            .Scrollable()
            .Filterable()
            .HtmlAttributes(new { style = "height:430px;" })
            .DataSource(dataSource => dataSource
                .Ajax()
                .ServerOperation(false)
                .Batch(true)
                .Model(model1 =>
                {
                    model1.Id(p1 => p1.ApprovalID);
                    //model1.Field(p1 => p1.ChecklistItemDateID).Editable(false);
                    //model1.Field(p1 => p1.SubmitterID).Editable(false);
                    //model1.Field(p1 => p1.ApproverID).Editable(false);
 
                })
                .Read(read => read.Action("ChecklistApproval_Read", "Checklist"))
                .Update(update => update.Action("ChecklistApproval_Update", "Checklist"))
    )
 
 )
}
    </div>
<script type="text/javascript">
    function error_handler(e) {   
        if (e.errors) {
            var message = "Errors:\n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function() {
                        message += this + "\n";
                    });
                }
            });       
            alert(message);
        }
    }
</script>

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 11 Jun 2013, 03:12 PM
Hello Rick,

The exception is caused by the "Stirng" editor template. The model type specified for the editor is string and MVC uses it for all types for which a different editor is not found. The problem is fixed in the service pack and in the latest internal builds. You could also avoid the problem by modifying the editor as in the snippet below:

@model object
 
@Html.TextBoxFor(model => model, new {@class="k-textbox" })
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Rick
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or