or
@(Html.Kendo().Grid(Model.Products)
.Name("FabricGrid")
.Columns(columns =>
{
columns.Bound(p => p.Fabric);
columns.Bound(p => p.Pattern);
columns.Bound(p => p.Description);
columns.Bound(p => p.UPrice);
columns.Bound(p => p.Qty).Width(150);
columns.Bound(p => p.Total);
columns.Command(command => command.Edit()).Width(110);
columns.Command(command => command.Destroy()).Width(110);
})
.Scrollable()
.Sortable()
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Model(model => model.Id(p => p.ProductId))
.Events(events => events.Error("error_handler"))
.Update(update => update.Action("Product_Update", "ShoppingCart"))
.Destroy(destroy => destroy.Action("Product_Delete", "ShoppingCart"))
)
)
<%:Html.Kendo().Grid(Model)
.Name("players")
.Columns(columns =>
{
columns.Bound(p => p.FullName);
columns.Bound(p => p.MobilePhone);
columns.Bound(p => p.EmailAddress);
columns.Command(command =>
{
command.Edit();
command.Destroy();
}).Width(200);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Model(model => model.Id(p => p.PlayerId))
.Read(read => read.Action("Edit", "Player"))
.Update(update => update.Action("Edit", "Player"))
.Destroy(update => update.Action("Delete", "Player")))
%>
<%:Html.Kendo().Grid(Model)
.Name("articles")
.Columns(columns =>
{
columns.Bound(a => a.Date);
columns.Bound(a => a.Title);
columns.Command(command =>
{
command.Edit();
command.Destroy();
}).Width(200);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Model(model => model.Id(a => a.ArticleId))
.Read(read => read.Action("Edit", "Article"))
.Update(update => update.Action("Edit", "Article"))
.Destroy(destroy => destroy.Action("Delete", "Article")))
%>
namespace RfPrMvcKendo.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
DataTable table = new DataTable();
table.Columns.AddRange(new DataColumn[] {
new DataColumn("Counter1", typeof(int)),
new DataColumn("Counter2", typeof(int)),
new DataColumn("Counter3", typeof(int)),
new DataColumn("Counter4", typeof(int)),
new DataColumn("Counter5", typeof(int)) });
table.Rows.Add(10, 25, 31, 45, 80);
return View(table);
}
}
}
The model item passed into the dictionary is of type 'System.Double', but this dictionary requires a model item of type 'System.String'.
The model item passed into the dictionary is of type 'System.Double', but this dictionary requires a model item of type 'System.String'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Double', but this dictionary requires a model item of type 'System.String'.
Source Error:
Line 53:
Line 54: <
script
id
=
"template"
type
=
"text/kendo-tmpl"
>
Line 55: @(Html.Kendo().Grid<
Toolbox.Web.Models.RebateAverageCostViewModel
>()
Line 56: .Name("grid_#=ID#")
Line 57: .Columns(columns =>
Source File: c:\Data\Source\Work\2\Wilco\Toolbox\Main\Toolbox.Web\Views\RebateAverageCosts\Index.cshtml Line: 55
Stack Trace:
[InvalidOperationException: The model item passed into the dictionary is of type 'System.Double', but this dictionary requires a model item of type 'System.String'.]
System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value) +584415
System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) +371
System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData) +48
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +98
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
System.Web.Mvc.Html.TemplateHelpers.ExecuteTemplate(HtmlHelper html, ViewDataDictionary viewData, String templateName, DataBoundControlMode mode, GetViewNamesDelegate getViewNames, GetDefaultActionsDelegate getDefaultActions) +579
System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData, ExecuteTemplateDelegate executeTemplate) +1002
System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData) +66
System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper`1 html, Expression`1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData, TemplateHelperDelegate templateHelper) +117
System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper`1 html, Expression`1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData) +104
System.Web.Mvc.Html.EditorExtensions.EditorFor(HtmlHelper`1 html, Expression`1 expression, Object additionalViewData) +62
Kendo.Mvc.UI.Html.GridEditorForCellBuilder`2.AppendEditorFor(HtmlHelper`1 htmlHelper, IHtmlNode container) +62
Kendo.Mvc.UI.Html.GridEditorForCellBuilder`2.AppendEditor(IHtmlNode container, HtmlHelper`1 htmlHelper) +52
.... snip .....
@(Html.Kendo().Grid<
Toolbox.Web.Models.RebateAverageCostItemViewModel
>()
.Name("grid")
.DataSource(dataSource => dataSource // Configure the grid data source
.Ajax() // Specify that ajax binding is used
//.Batch(true) // Enable batch updates
.Model(model =>
{
model.Id(item => item.ID); // Specify the property which is the unique identifier of the model
model.Field(item => item.ID).Editable(false); // Make the property not editable
})
.Read(read => read.Action("RebateAverageCostItems_Read", "RebateAverageCosts")) // Set the action method which will return the data in JSON format
)
.Columns(columns =>
{
columns.Bound(c => c.ID).Width(10);
columns.Bound(c => c.ItemNo).Width(100);
columns.Bound(c => c.ProductDescription).Width(200);
columns.Bound(c => c.ProductGroup).Width(100);
columns.Bound(c => c.PackSize).Width(100);
columns.Bound(c => c.Supplier).Width(100);
columns.Bound(c => c.PriceUOM).Width(100);
})
//.Editable(editable => editable.Mode(GridEditMode.InCell)) // Use in-cell editing mode
.Pageable() // Enable paging
.Sortable() // Enable sorting
.Filterable() // Endable filtering
.ClientDetailTemplateId("template")
.Events(events => events.DataBound("dataBound"))
)
<
script
id
=
"template"
type
=
"text/kendo-tmpl"
>
@(Html.Kendo().Grid<
Toolbox.Web.Models.RebateAverageCostViewModel
>()
.Name("grid_#=ID#")
.Columns(columns =>
{
columns.Bound(c => c.ID).Width(10);
columns.Bound(c => c.BeginDate);
columns.Bound(c => c.EndDate);
columns.Bound(c => c.NetCostAfterRebate);
})
.DataSource(dataSource => dataSource
.Ajax() // Specify that ajax binding is used
.Batch(true) // Enable batch updates
.Model(model =>
{
model.Id(item => item.ID); // Specify the property which is the unique identifier of the model
model.Field(item => item.ID).Editable(false); // Make the property not editable
})
.Read(read => read.Action("RebateAverageCosts_Read", "RebateAverageCosts", new { rebateAverageCostItemId = "#=ID#" }))
)
// Note if I comment out this line, it works in read only mode....
.Editable(editable => editable.Mode(GridEditMode.InCell)) // Use in-cell editing mode
.Pageable() // Enable paging
.Sortable() // Enable sorting
.ToClientTemplate()
)
</
script
>
I've done some digging myself on my side by logging the grid's Edit event, and I can verify that the event is not being fired when the first cell is highlighted, but it is being fired when that last tab occurs (when the second column becomes a text field).
Does there happen to be a simple way of resolving this issue that I'm overlooking?
Thanks.