This question is locked. New answers and comments are not allowed.
I am really struggling to get this working, the EditorTemplate model is always null when a complex type is used, when a simple type is used it works perfectly. I have followed all the instructions on this page but the instructions don't seem to work for me so I'm hoping some expert here can help me.
I have the following Order model:
With the following Gallery.Simple model (the return type from property Gallery above):
In my view I have this code:
My display template (which works fine by the way):
My editor template (which always returns true - i.e. null when I click on the column to start editing it in the browser):
If anyone has any ideas I'm completely open, I've been pulling my hair out over this and I'm fairly sure that it is something stupid I'm doing as I've only been using MVC for a couple of weeks.
Thanks in advance
I have the following Order model:
public class Order {
[ScaffoldColumn(false)]
public Guid Identifier { get; private set; }
[Required, ReadOnly(true)]
public int? CTID { get; set; }
[Required]
public string Customer { get; set; }
[Required, UIHint("Gallery")]
public Gallery.Simple Gallery { get; set; }
public static IQueryable<
Order
> Create() {
var context = new Context();
var query = context.Orders.Select(order => order);
return query.Select(order => new Order {
Customer = order.Customer.DisplayName,
CTID = order.CTID,
Gallery = new Gallery.Views.Simple { Identifier = order.Gallery.Identifier, Name = order.Gallery.ShortName },
Identifier = order.Identifier
});
}
}
With the following Gallery.Simple model (the return type from property Gallery above):
[Serializable]
[TypeConverter(typeof(ConvertibleToString))]
public class Simple {
public Guid Identifier { get; set; }
public string Name { get; set; }
}
public class ConvertibleToString : TypeConverter {
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
return (sourceType == typeof(string)) ? true : base.CanConvertFrom(context, sourceType);
}
}
In my view I have this code:
@model IQueryable<
Order
>
@using Telerik.Web.Mvc.UI;
@{
Html.Telerik().Grid(Model)
.Name("Orders")
.HtmlAttributes(new { style="position:absolute;top:200px;left:50px;right:50px;" })
.Columns(column => {
column.Bound(order => order.CTID).Width(80);
column.Bound(order => order.Gallery).Width(200);
column.Bound(order => order.Customer).Width("auto");
})
.DataKeys(keys => { keys.Add(order => order.Identifier); })
.DataBinding(dataBinding => dataBinding
.Ajax()
.Update("_Update", "Orders")
)
.Editable(editing => editing.Mode(GridEditMode.InCell))
.Scrollable(scrolling => scrolling.Enabled(true).Height(670))
.Sortable(sorting => sorting.Enabled(true).OrderBy(order => order.Add(model => model.CTID).Ascending()))
.Pageable(paging => paging.Enabled(true).PageSize(24))
.Filterable(filtering => filtering.Enabled(true))
.Footer(true)
.Render();
}
My display template (which works fine by the way):
@model Gallery.Simple
@Model.Name
My editor template (which always returns true - i.e. null when I click on the column to start editing it in the browser):
@model Gallery.Simple
@(Model==null)
If anyone has any ideas I'm completely open, I've been pulling my hair out over this and I'm fairly sure that it is something stupid I'm doing as I've only been using MVC for a couple of weeks.
Thanks in advance