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

[Solved] Editor template not showing when editing

5 Answers 239 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mattias
Top achievements
Rank 1
Mattias asked on 23 Nov 2010, 11:51 AM
Hi,
I think I have tried every possible way now to show the template but nothing works! :(
I have this model:
public class Resource
{
        [ScaffoldColumn(false)]
        public virtual Guid ID { get; private set; }
 
        [Required(ErrorMessage="Namn obligatorisk")]
        [StringLength(128)]
        [DisplayName("Namn")]
        [UIHint("TextBoxLarge")]
        public virtual string ResourceName { get; set; }
 
        [Required(ErrorMessage = "Klient obligatorisk")]
        [DisplayName("Klient")]
        [UIHint("DropDownList")]
        public virtual Client Client { get; set; }
}

And I have a editor template, DropDownList.ascx with the dropdownlist.
The grid looks like this:
<%
     Html.Telerik().Grid(Model)
        .Name("Grid")
        .DataKeys(keys => keys.Add(x => x.ID).RouteKey("id"))
        .ToolBar(commands => commands.Insert())
         
        .DataBinding(dataBinding =>
        {
            dataBinding.Server()
                .Select("Index", "Resource")
                .Insert("Insert", "Resource")
                .Update("Update", "Resource")
                .Delete("Delete", "Resource");
        })
        .Editable(editing => editing.Mode(GridEditMode.InForm))
         
        .Columns(columns =>
        {
            columns.Bound(x => x.ResourceName).Title(Resources.Shared.Resource);
            columns.Bound(x => x.Client.ClientName).Title(Resources.Shared.Client);
            columns.Bound(x => x.City.CityName).Title(Resources.Shared.City);
            columns.Bound(x => x.CreateDate).Title(Resources.Shared.CreateDate).ReadOnly();
 
            columns.Command(commands =>
                {
                    commands.Edit();
                    commands.Delete();
                }).Width(180).Title("").HtmlAttributes(new { @style = "text-align:right" });
        })
        .Render();
    %>

But when I edit a row in the grid it just showing the textbox for ResourceName but no dropdownlist for the Client.
Any ideas why?

Regards,
Mattias


5 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 23 Nov 2010, 12:13 PM
Hi Mattias,

You seem to have hit a well known ASP.NET MVC limitation. You can check my blog post which shows why it does not work by default and what the workaround is.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mattias
Top achievements
Rank 1
answered on 23 Nov 2010, 12:55 PM
Thanks Atanas for the link, now I understand whats going on.

But how stupid this is! :( Do you know if this is the case in MVC 3 to?
0
Atanas Korchev
Telerik team
answered on 23 Nov 2010, 03:07 PM
Hi Mattias,

 I think yes. The bug report in codeplex got closed as "by design".

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mattias
Top achievements
Rank 1
answered on 23 Nov 2010, 03:14 PM
Ok.

What do you think of this workaround?
Instead of making a complete editor template for the whole class I'm adding a "value" property to the class like this:
public class Resource
{
        [ScaffoldColumn(false)]
        public virtual Guid ID { get; private set; }
  
        [Required(ErrorMessage="Namn obligatorisk")]
        [StringLength(128)]
        [DisplayName("Namn")]
        [UIHint("TextBoxLarge")]
        public virtual string ResourceName { get; set; }
  
        [ScaffoldColumn(false)]
        public virtual Client Client { get; set; }
 
        [Required(ErrorMessage = "Klient obligatorisk")]
        [DisplayName("Klient")]
        [UIHint("DropDownList")]
        public virtual Guid ClientID { get; set; }
}

This is working but I am not sure it's a good solution?
0
Atanas Korchev
Telerik team
answered on 23 Nov 2010, 03:41 PM
Hi Mattias,

 Yes, this is a viable workaround. The other option is to make a custom editor template for the Resource type. However I think your approach  involves less code.

All the best,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Mattias
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Mattias
Top achievements
Rank 1
Share this question
or