ListView editable not working with complex objects

4 posts, 0 answers
  1. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 26 Aug 2013 Link to this post

    EditorTemplate:

    <
    div class="k-widget">
        @Html.HiddenFor(model => model.Id)
        <div class="edit-buttons">
            <a class="k-button k-button-icontext k-update-button" href="\\#"><span class="k-icon k-update"></span></a>
            <a class="k-button k-button-icontext k-cancel-button" href="\\#"><span class="k-icon k-cancel"></span></a>
        </div>
        <dl>
            <dt>
                @Html.LabelFor(model => model.SharedWith)
            </dt>
            <dd>
                @(Html.Kendo().MultiSelectFor(model => model.SharedWith)
                    .DataValueField("Id")
                    .DataTextField("Name")
                    .Placeholder("Type user's name...")
                    .DataSource(source =>
                    {
                        source.Read(read =>
                        {
                            read.Action("Users", "User");
                        });
                    })
                    .TagTemplate("<div class=""tag-image""><img src=""#: Picture #"" height=""32"" /></div>")
                    .ItemTemplate("<div class=""item-image""><img src=""#: Picture #"" height=""32"" /></div>"))
            </dd>
        </dl>
    </div>
    The list view display mode works fine, but as soon as I click edit, and it switches to the EditorTemplate, I get an error saying that Picture is undefined, even though the model that is being passed into the ListView constructor definitely has a fully populated SharedWith model.
  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 28 Aug 2013 Link to this post

    Hello Matt,

    The template seems to be specified for the MultiSelect widget in the editor. Does the result from the Users action method contain a field name "Picture"?

    Regards,
    Daniel
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 28 Aug 2013 Link to this post

    Yes, it does.

    The EditorTemplate works fine when it's called from a view, but when it's triggered by clicking edit from the ListView, javascript gives an error saying that Picture is not defined.
  5. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 30 Aug 2013 Link to this post

    Hello again Matt,

    Thank you for confirming. It seems that the problem occurs because the expression is used in a nested template and is not evaluated in the correct context. Please try to escape the "#" characters in the multiselect template and let me know if you still experience this problem:

    .TagTemplate("<div class=""tag-image""><img src=""\\#: Picture \\#"" height=""32"" /></div>")
    .ItemTemplate("<div class=""item-image""><img src=""\\#: Picture \\#"" height=""32"" /></div>"))
    Regards,
    Daniel
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready