using System.Web.Mvc; using System.Web.Mvc.Ajax; namespace ChadSoft.Web.Mvc.Filters { public class EnablePartialRenderingAttribute : ActionFilterAttribute { public override void OnActionExecuted(ActionExecutedContext filterContext) { // We only care about AJAX requests, so if this isn't one, just return if (!filterContext.HttpContext.Request.IsMvcAjaxRequest()) return; // Grab the existing result and cast it to a ViewResult var result = filterContext.Result as ViewResult; // Replace the result with a PartialViewResult filterContext.Result = new PartialViewResult { TempData = result.TempData, ViewData = result.ViewData, ViewName = string.Format("Partial_{0}", result.ViewName) }; } } }