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

[Solved] Object EditorTemplate not working with Grid Ajax()

2 Answers 50 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.
Jose
Top achievements
Rank 1
Jose asked on 28 Sep 2011, 08:35 PM
Hello...

Following this article
http://www.telerik.com/community/code-library/aspnet-mvc/grid/custom-popup-editor-form.aspx

I tried to create an Object EditorTemplate for my Grid for Ajax Editing.

The Grid does show the popup with the EditorTemplate, but all the values are null.
Actually a set a step on in the cshtml file and it triggers only once and the model passed in a brand new instance of the object.
i am attaching my cshtml here.
thanks

@model object
@{
    if (Model == null)
    {
    @ViewData.ModelMetadata.NullDisplayText
    }
    else if (ViewData.TemplateInfo.TemplateDepth > 1)
    {
    @ViewData.ModelMetadata.SimpleDisplayText
    }
    else
    {
        using (Html.BeginIFGSection(false, ""))
        {
            foreach (var prop in ViewData.ModelMetadata.Properties.Where(x => x.ShowForDisplay && !ViewData.TemplateInfo.Visited(x)))
            {
                if (prop.HideSurroundingHtml)
                {
                    @Html.Display(prop.PropertyName)
                }
                else
                {
                    @String.Format("{0} | {1} -> ",prop.GetDisplayName(), Html.Display(prop.PropertyName))
                }
            }
        }
    }
}

2 Answers, 1 is accepted

Sort by
0
Jose
Top achievements
Rank 1
answered on 30 Sep 2011, 03:05 PM
nobody? :(
0
Rosen
Telerik team
answered on 30 Sep 2011, 03:54 PM
Hi Jose,

I'm afraid that this is a known limitation and such code is not supported during ajax editing.
As you may known when grid is populated through ajax binding, editor templates will be serialized to string templates and then rendered on the client when grid enters edit mode. Therefore, no server code will be executed during the actual template rendering. Another thing you should have in mind is that during their serialization templates will be instantiated and a default instance of the model will be passed. 

The client OnEdit event can be used to modify the content of the edit form.

Regards,
Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Jose
Top achievements
Rank 1
Answers by
Jose
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or