Changing from DataList to UnOrderedList

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 12 ans
I'm using version 2.3 and I'm trying to change the HomePageProducts view from a DataList which renders as a table to an UnOrderedList (UL & LI's)

I've created a HTML Helper

public static IHtmlString UnorderedList<T>(this HtmlHelper helper, string listID, IEnumerable<T> items, int columns,
            Func<T, HelperResult> template)
            where T : class
        {
            if (items == null)
                return new HtmlString("");

            var sb = new StringBuilder();

            sb.Append("<ul ");
            sb.Append("id=");
            sb.Append(listID);
            sb.Append(">");

            foreach (T item in items)
            {
                sb.AppendFormat("<li>{0}</li>", HttpUtility.HtmlEncode(item.ToString()));
            }

            sb.Append("</ul>");

            return new HtmlString(sb.ToString());
        }


and modified the HomePageProducts view to:

@model HomePageProductsModel
@using Nop.Web.Framework.UI;
@using Nop.Web.Models.Catalog;
@if (Model.Products.Count > 0)
{
    <div class="list_carousel">
            @(Html.UnorderedList<ProductModel>("foo0", Model.Products, 40,
            //@(Html.DataList<ProductModel>(Model.Products, 3,
            @<li>
                @Html.Partial("_ProductSmallBox", @item)
            </li>
            ))
    </div>
}


but instead of showing the Products via the partial view _ProductSmallBox I'm now getting a LI containing "Nop.Web.Models.Catalog.ProductModel"
Il y a 12 ans
why is it you always think of something once your posted in public......

I changed the HTML helper to this:

public static IHtmlString UnorderedList<T>(this HtmlHelper helper, string listID, IEnumerable<T> items, int columns,
            Func<T, HelperResult> template)
            where T : class
        {
            if (items == null)
                return new HtmlString("");

            var sb = new StringBuilder();

            sb.Append("<ul ");
            sb.Append("id=");
            sb.Append(listID);
            sb.Append(">");

            foreach (T item in items)
            {
                //sb.AppendFormat("<li>{0}</li>", HttpUtility.HtmlEncode(item.ToString()));
                sb.Append("<li>");
                sb.Append(template(item).ToHtmlString());
                sb.Append("</li>");
            }

            sb.Append("</ul>");

            return new HtmlString(sb.ToString());
        }


and modified the view slightly as well:

@model HomePageProductsModel
@using Nop.Web.Framework.UI;
@using Nop.Web.Models.Catalog;
@if (Model.Products.Count > 0)
{
    <div class="list_carousel">
            @(Html.UnorderedList<ProductModel>("foo0", Model.Products, 40,
            //@(Html.DataList<ProductModel>(Model.Products, 3,
            @<div>
                @Html.Partial("_ProductSmallBox", @item)
            </div>
            ))
    </div>
}


I now have an unordered list of items on the homepage that can be put into a jQuery Carousel !!
Il y a 11 ans
hi, i might ask a dumb question1 where did u create the HTMLHelper ??

RESOLVE : okey i got it, for those who are like me should find it in Nop.Web.Framework > DataListExtensions.cs and change permanently   am i right?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.