diff --git a/Ch03/03_03_End/Website/Helpers/ProductHelpers.cs b/Ch03/03_03_End/Website/Helpers/ProductHelpers.cs new file mode 100644 index 0000000..8e18620 --- /dev/null +++ b/Ch03/03_03_End/Website/Helpers/ProductHelpers.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using System.Web.Mvc.Html; +using HPlusSports.Models; + +namespace HPlusSports +{ + public static class ProductHelpers + { + public static IHtmlString Rating(this System.Web.Mvc.HtmlHelper html, ProductRating rating) + { + if (rating == null || rating.ReviewCount == 0) + { + return new MvcHtmlString("No Rating"); + } + return html.Partial("_Rating", rating); + } + } +} \ No newline at end of file diff --git a/Ch03/03_03_End/Website/Views/Products/ProductList.cshtml b/Ch03/03_03_End/Website/Views/Products/ProductList.cshtml index 6d20a19..6e7b26f 100644 --- a/Ch03/03_03_End/Website/Views/Products/ProductList.cshtml +++ b/Ch03/03_03_End/Website/Views/Products/ProductList.cshtml @@ -34,7 +34,7 @@ }
- @Html.Rating(rating) + @Html.Rating(rating)