Reputation: 825
I am using Telerik MVC Grid, with ajax binding and I use grid editing in InCell editing mode with editor templates. I would like to pass model to the editors.
As I know if I had used the server binding, it could be possible to pass the model to the editor templates. But I am not sure about Ajax binding.
Is it possible to pass a model to editor templates when you use Ajax binding?
Upvotes: 2
Views: 3260
Reputation: 143
There is also the new feature of Telerik Mvc Grid called: ForeignKey, that allow you to do abstraction of the editor template and providing it simply the SelectList (or IEnumerable). Here is an example of it.
columns.ForeignKey(o => o.EmployeeID, (IEnumerable)ViewData["employees"],
"ID", "Name").Width(230);
By default it is using drop down list, you can change that by client template.
Upvotes: 0
Reputation: 9034
Yes you can! It does it automatically. just if your template editor is a list box , you should pass the list items through a ViewBag.XXX property. Here is an example of ProductSelector.ascx editor template :
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<int>" %>
<%Html.Telerik().ComboBox()
.Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
.AutoFill(true)
.BindTo(((IEnumerable<Aien.CRM.Biz.Entities.Product>)ViewBag.PossibleProducts).Select(option => new SelectListItem
{
Text = (option == null ? "(None)" : option.Title),
Value = option.Id.ToString()
}))
.OpenOnFocus(true)
.Render();
%>
don't forget to put a UiHint attribute for the related model property.
Upvotes: 1