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

A data is always null in the Editor Template

5 Answers 155 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.
Sergey
Top achievements
Rank 1
Sergey asked on 06 Oct 2010, 01:47 PM
I want to have my own Editor Template for editing string data, but the data is always null, when I use Ajax binding, and all is right, when I'm using server side binding.

Model
[KnownType(typeof(Post))]
public class Post
{
    public Post()
    {
    }
 
    [ScaffoldColumn(false)]
    public int Id { get; set; }
 
    public string Title { get; set; }
 
    //[DisplayFormat(ApplyFormatInEditMode = true)]
    [UIHint("PostContent")]
    public string PostContent { get; set; }
 
    public string Tags { get; set; }
 
    [HiddenInput]
    [ReadOnly(true)]
    public DateTime CreatedDate { get; set; }
 
    [ScaffoldColumn(false)]
    [HiddenInput]
    [ReadOnly(true)]
    public DateTime LastUpdatedDate { get; set; }
}

Controller Action
[GridAction]
public ActionResult Index()
{
    var posts = PostRepository.GetAll();
 
    if (Request.IsAjaxRequest())
        return View(new GridModel(posts));
 
    return View(posts);
}

View (Grid with Ajax binding)
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
    <% Html.Telerik().Grid(Model)
        .Name("Grid")
        .DataKeys(dataKeys => dataKeys.Add(m => m.Id))
        .DataBinding(dataBinding =>
            {
                dataBinding.Ajax().Select("Index", "Home");
                dataBinding.Ajax().Insert("Create", "Home");
                dataBinding.Ajax().Update("Edit", "Home");
                dataBinding.Ajax().Delete("Delete", "Home");
            })
        .Columns(columns =>
            {
                columns.Command(commands =>
                    {
                        commands.Edit();
                        commands.Delete();
                    }).Width(80);
                columns.Bound(m => m.Title).Title("Title");
                columns.Bound(m => m.PostContent).Title("Content");
                columns.Bound(m => m.Tags).Title("Tags");
                columns.Bound(m => m.CreatedDate).Title("Created At");
            })
        .Pageable(pager => pager.PageSize(10))
        .Sortable()
        .Editable(editing => editing.Mode(GridEditMode.InForm))
        .Filterable()
        .Render();
    %>
</asp:Content>

Editor Template
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.String>" %>
 
<p>test</p>
<p>
<%=
  Model // The model is always null, when I use Ajax binding,
        // and all is right with server binding
%></p>
<p>test</p>

In attach there is small example, that demonstrates this bug (Visual Studio 2008, MVC2)

5 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 06 Oct 2010, 03:38 PM
Hello Sergii,

This is a known limitation which unfortunately cannot be resolved. During ajax binding we instantiate a dummy model object by calling Activator.CreateInstance and render all editors for the columns because we need them on the client-side. It is not possible to invoke the editor template with all the valid values as it is created entirely on the client-side. That's why Model is null in this case.

If you need the actual model value on the client-side you can use the OnEdit client-side event and populate the editor template there.

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
Sergey
Top achievements
Rank 1
answered on 07 Oct 2010, 07:13 AM
Thank you, for the reply, I'll try to use OnEdit event.
0
Kevin
Top achievements
Rank 1
answered on 13 Sep 2011, 01:14 AM
OK, so when I try to use the onEdit event I try to change the outerHTML of a column and I get like an "unknown error".  This is rediculous.  I just want an editor template that displays the string value of the column and a button next to it that does something.  Forget about the button, that's easy, I can't even display the string value.  
0
Travis
Top achievements
Rank 1
answered on 14 Sep 2011, 05:03 PM
Is this still a limitation?  I've noticed that whenever I use a telerik control in my editor template it works, but if I try to use a non-teleirk control like Html.TextBox the model value is always null. 
0
Rosen
Telerik team
answered on 15 Sep 2011, 08:09 AM
Hello Travis,

Unfortunately, this is still a limitation. Could you please make sure that the input element that is generated have the same name attribute as the property from which should be populated. Also you may use OnEdit event to manually bind edit form elements.

All the best,
Rosen
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
Sergey
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Sergey
Top achievements
Rank 1
Kevin
Top achievements
Rank 1
Travis
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or