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

Problem with ListView TagName

3 Answers 242 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Luca
Top achievements
Rank 2
Luca asked on 04 Oct 2017, 09:50 AM

I am using a ListView on .Net Core 2.0 the problem is the TagName attribute, no matter what i write inside it, it always render inside a div, here is my code, all works as expected except the TagName. The client template works, but i have <li> inside <div> instead of <ul>, html attributes render correctly.

Anyone knows where i am doing wrong?

@(Html.Kendo().ListView<MyModel>()
    .Name("LV_Notifiche")
    .TagName("ul")
    .HtmlAttributes(new { @class = "dropdown-menu-list scroller", style = "height: 250px;" })
    .ClientTemplateId("notificaTemplate")
    .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false)
        .Read(read => read.Action("Notifiche_Read", "Notification"))
    )
    .Deferred()
)

3 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 09 Oct 2017, 04:27 AM
Hi Luca,

We are aware of this bug and we have already logged a public item, where you could follow its progress:
Please excuse us for any inconvenience caused by this.


Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jonathan Landry
Top achievements
Rank 1
answered on 02 Nov 2017, 01:39 PM

In the mean time, here is a workaround. In my case, I use deferred, but you can change DeferredWidgetBuilder<ListView<T>> to ListViewBuilder<T>

public static class ListViewBuilderFixBugWrongTagNameExtensions
{
    public static string GetString(this IHtmlContent content)
    {
        var writer = new System.IO.StringWriter();
        content.WriteTo(writer, HtmlEncoder.Default);
        return writer.ToString();
    }
 
    public static IHtmlContent FixBugWrongTagName<T>(this DeferredWidgetBuilder<ListView<T>> listViewDeferredBuilder) where T : class
    {
        var tagName = listViewDeferredBuilder.ToComponent().TagName;
        if (tagName.Equals("div", StringComparison.OrdinalIgnoreCase))
        {
            return listViewDeferredBuilder;
        }
        else
        {
            var start = "<div ";
            var end = "</div>";
            var content = listViewDeferredBuilder.GetString();
            if (content.IndexOf(start) != 0)
            {
                throw new NotSupportedException();
            }
            if (content.LastIndexOf(end) != content.Length - end.Length)
            {
                throw new NotSupportedException();
            }
 
            var hcb = new HtmlContentBuilder();
            hcb.AppendHtml($"<{tagName} ");
            hcb.AppendHtml(content.Substring(start.Length, content.Length - start.Length - end.Length));
            hcb.AppendHtml($"</{tagName}>");
 
            return hcb;
        }
    }
}
0
Konstantin Dikov
Telerik team
answered on 06 Nov 2017, 03:40 PM
Hello Jonathan,

For sharing the workaround with the community you will find your Telerik Points update. I have also included the workaround in the public issue.


Kind Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ListView
Asked by
Luca
Top achievements
Rank 2
Answers by
Konstantin Dikov
Telerik team
Jonathan Landry
Top achievements
Rank 1
Share this question
or