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

[Solved] MVC Kendo Grid - Editable Template not binding

1 Answer 227 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 29 Sep 2014, 10:44 PM
I have a Kendo Grid that works fine if I use the built in popup editor, .Editable(editable => editable.Mode(GridEditMode.PopUp))                

If I switch to a custom template it won't bind the data. 

Any help is appreciated.

@(Html.Kendo().Grid<Application.Models.OrgHtmlContentViewModel>()
    .Name("ContentGrid")
    .Columns(columns =>
    {
        columns.Bound(c => c.OrgHtmlContentTypeName).Width(150).Title("Content Type");
        columns.Bound(c => c.HtmlContent).Width(600).Title("Html Content").Encoded(false);
        columns.Command(command => { command.Edit(); }).Width(100);
    })
    .HtmlAttributes(new { style = "height: 600px;" })
    .Scrollable()
    .Sortable()
    //.Editable(editable => editable.Mode(GridEditMode.PopUp))
    .Editable(editable => { editable.Mode(GridEditMode.PopUp); editable.TemplateName("OrgHtmlContentEditor").Window(w => w.Title("Org Html Content").Width(760)); })           
    .DataSource(dataSource => dataSource
        .Ajax()
        .Events(events => events.Error("error_handler"))
        .Model(model => model.Id(c => c.OrgHtmlContentId))
        .Read(read => read.Action("OrgHtmlContent_Read", "OrgHtmlContents", new { id = Model.OrganizationId }))
        .Update(update => update.Action("OrgHtmlContent_Update", "OrgHtmlContents"))
    )
)

Custom Editor
@model Application.Models.OrgHtmlContentViewModel
 
<div style="padding: 10px;">
   <h6>@Html.DisplayFor(m => m.OrgHtmlContentTypeName)</h6>
 
    @(Html.Kendo().EditorFor(c => c.HtmlContent)
          .Name("contentEditor")
          .HtmlAttributes(new { style = "width: 740px;height:440px" })
    )
</div>

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 01 Oct 2014, 10:30 AM
Hi Tim,

The reason for current behavior is that the editor template contain some invalid configuration:
  • "DisplayFor" helper cannot be used as the editor template is evaluated on the server side using empty instance of the Grid type (later on the client side current model is bind to the generated html).
  • When the strongly-typed MVC helper is used you should avoid setting the "Name" option of the widget as it's used on the client side to find the matching field in currently edited model.
Please check the updated editor template below:
@model Application.Models.OrgHtmlContentViewModel
  
<div style="padding: 10px;">
   <h6>${data.OrgHtmlContentTypeName}</h6>
  
    @(Html.Kendo().EditorFor(c => c.HtmlContent)
          .HtmlAttributes(new { style = "width: 740px;height:440px" })
    )
</div>

Regards,
Vladimir Iliev
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
Tim
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or