Exercise Files
This commit is contained in:
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace HPlusSports.Extensions
|
||||
{
|
||||
public class AllowPartialRenderingAttribute : ActionFilterAttribute
|
||||
{
|
||||
public override void OnActionExecuted(ActionExecutedContext filterContext)
|
||||
{
|
||||
var request = filterContext.HttpContext.Request;
|
||||
var result = filterContext.Result as ViewResult;
|
||||
|
||||
if (request == null)
|
||||
return;
|
||||
|
||||
if (request.IsAjaxRequest())
|
||||
{
|
||||
filterContext.Result = new PartialViewResult
|
||||
{
|
||||
TempData = result.TempData,
|
||||
View = result.View,
|
||||
ViewData = result.ViewData,
|
||||
ViewEngineCollection = result.ViewEngineCollection,
|
||||
ViewName = result.ViewName,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
Ch05/05_02_Begin/Website/Extensions/HtmlHelperExtensions.cs
Normal file
23
Ch05/05_02_Begin/Website/Extensions/HtmlHelperExtensions.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc.Html;
|
||||
|
||||
namespace HPlusSports
|
||||
{
|
||||
public static class HtmlHelperExtensions
|
||||
{
|
||||
|
||||
public static IHtmlString Rating(this System.Web.Mvc.HtmlHelper html, Models.ProductRating rating)
|
||||
{
|
||||
if (rating == null || rating.ReviewCount == 0)
|
||||
{
|
||||
return new System.Web.Mvc.MvcHtmlString("<span><em>No Rating</em></span>");
|
||||
}
|
||||
|
||||
return html.Partial("_Rating", rating);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
22
Ch05/05_02_Begin/Website/Extensions/TempDataExtensions.cs
Normal file
22
Ch05/05_02_Begin/Website/Extensions/TempDataExtensions.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace HPlusSports
|
||||
{
|
||||
public static class TempDataExtensions
|
||||
{
|
||||
const string SuccessMessageKey = "SuccessMessage";
|
||||
|
||||
public static string SuccessMessage(this System.Web.Mvc.TempDataDictionary tempData)
|
||||
{
|
||||
return tempData[SuccessMessageKey] as string;
|
||||
}
|
||||
|
||||
public static void SuccessMessage(this System.Web.Mvc.TempDataDictionary tempData, string successMessage)
|
||||
{
|
||||
tempData[SuccessMessageKey] = successMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Ch05/05_02_Begin/Website/Extensions/UrlHelperExtensions.cs
Normal file
21
Ch05/05_02_Begin/Website/Extensions/UrlHelperExtensions.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using HPlusSports.Models;
|
||||
|
||||
namespace HPlusSports
|
||||
{
|
||||
public static class UrlHelperExtensions
|
||||
{
|
||||
public static string Product(this System.Web.Mvc.UrlHelper urlHelper, Product product)
|
||||
{
|
||||
return Product(urlHelper, product?.SKU);
|
||||
}
|
||||
|
||||
public static string Product(this System.Web.Mvc.UrlHelper urlHelper, string sku)
|
||||
{
|
||||
return urlHelper.Action("Product", "Products", new { id = sku });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user