Telerik MVC Grid AJAX Delete Results in Exception
I'm using Telerik's Grid control from the MVC Extensions. I have it set up to use action methods on the controller to perform select, insert, update, and delete via AJAX calls. I have an Edit command button in each row that displays a pop-up form to edit or create the entities displayed in the grid. I have also defined an template for the object type in EditorTemplates. This is all functioning as expected. The problem comes when I try to also add the Delete command button in the row. It results in this exception:
Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
I've verified that this is related to the editor template I'm using as Edit/Delete work properly without one. I fail to see how the Delete command and an editor template conflict with each other. Is this a Telerik bug? I've tried their forums and not have any responses.
Here's the code:
this.Html.Telerik().Grid(this.Model.RuleSet.ValueRules)
.Name("ValueRuleGrid")
.DataKeys(keys => { keys.Add<Int64>(r => r.ID); })
.DataBinding(binding => {
binding.Ajax()
.Select(this.Model.AjaxSelectMethod)
.Insert(this.Model.AjaxInsertMethod)
.Update(this.Model.AjaxUpdateMethod)
.Delete(this.Model.AjaxDeleteMethod)
;
})
.Columns(columns => {
columns.Bound(r => r.Section.Name).Title("Section");
columns.Bound(r => r.ItemName).Title("Question Code");
columns.Bound(r => r.Expression);
columns.Bound(r => r.Result);
columns.Command(commands => {
commands.Edit();
// FIX: When this is not commented out
// the page can't be loaded and results in an exception
//commands.Delete();
}).Width(200);
})
.ToolBar(toolbar => {
toolbar.Insert().ButtonType(GridButtonType.ImageAndText);
})
.Pageable(paging => {
paging.PageSize(6);
})
.Editable(editor => {
editor.Mode(GridEditMode.PopUp);
})
.Filterable()
.Sortable(sorting => {
sorting.Enabled(true);
sorting.SortMode(GridSortMode.MultipleColumn);
sorting.OrderBy(t => t.Add(vr => vr.SectionName));
sorting.OrderBy(t => t.Add(vr => vr.ItemName));
sorting.OrderBy(t => t.Add(vr => vr.Result));
})
.Render();
And this is the editor template:
<script type = "text/javascript">
function onChange_SectionName(e) {
var sectionName = $("#SectionName").data("tAutoComplete").value();
var itemName = $('#ItemName').data('tAutoComplete');
itemName.value("");
if (sectionName.length > 0) {
itemName.ajax.selectUrl =
'<%:
this.Url.Action("GetSectionItemNames", "Scoring")
%>?sectionName=' + sectionName;
$('#ItemName').attr("disabled", "");
}
else {
$('#ItemName').attr("disabled", "disabled");
}
}
</script>
<table>
<tr>
<td>Section:</td>
<td><%: this.Html.HiddenFor(vr => vr.ID) %>
<% this.Html.Telerik().AutoComplete()
.Name("SectionName")
.DataBinding(binding => {
binding.Ajax()
.Cache(true)
.Select("GetSectionNames", "Scoring");
})
.ClientEvents(events => {
events.OnChange("onChange_SectionName");
})
.Filterable(filtering => {
filtering.FilterMode(AutoCompleteFilterMode.Contains);
filtering.MinimumChars(1);
})
.AutoFill(true)
.Multiple(m => m.Enabled(false))
.HighlightFirstMatch(true)
.Render(); %></td>
</tr>
<tr>
<td>Item:</td>
<td><% this.Html.Telerik().AutoComplete()
.Name("ItemName")
.DataBinding(binding => {
binding.Ajax()
.Cache(false)
.Select("GetSectionItemNames", "Scoring", new {
sectionName = ""
});
})
.Filterable(filtering => {
filtering.FilterMode(AutoCompleteFilterMode.Contains);
filtering.MinimumChars(1);
})
.AutoFill(true)
.Multiple(m => m.Enabled(false))
.HighlightFirstMatch(true)
.Render(); %></td>
</tr>
<tr>
<td>Operator:</td>
<td><% this.Html.RenderAction("RuleOperatorComboBox", "Scoring", new {
valueRule = this.Model
}); %></td>
</tr>
<tr>
<td>Value 1:</td>
<td><%: this.Html.TextBoxFor(r => r.Value1) %></td>
</tr>
<tr>
<td>Value 2:</td>
<td><%: this.Html.TextBoxFor(r => r.Value2) %></td>
</tr>
&l开发者_运维知识库t;tr>
<td>Result/Weight:</td>
<td><% this.Html.Telerik().NumericTextBoxFor(vr => vr.Result)
.MinValue(1)
.MaxValue(500)
.DecimalDigits(0)
.Value(1)
.Render(); %></td>
</tr>
</table>
If I get rid of the editor template the Telerik grid plays nicely. Unfortunately, the default editors leave a lot to be desired in a production application.
As it turns out this appears to have been a bug with the MVC extensions from Telerik. I haven't gone through their release notes yet, but I did download and install the latest this morning. This particular error no longer creeps up.
There are some other nice features they've added, too. One of the big ones for me is batch in-cell editing. =)
I tried to search around a bit on the Telerik forums to see where your response on that site might be, but if it's similar to the one here I do have a quick tip for you. Be sure to include code snippets to go along with your description, as your implementation might be the culprit.
I highly recommend following up in the particular thread in the Telerik forums if you did not include code in your first post, as the code will allow someone to take a bit of a better look at why you're getting this error.
精彩评论