November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Depends on what you want to do but for example a custom action filter lets you run code before the action is called.
Yeah, I guessed as much. I just thought that there was some better way of implementing it.
Thanks!
This is what I did:
[TemplateDescriptor(Inherited = true)] [LoadCustomData] public class DefaultPageController : PageController<PageData> { public virtual ActionResult Index(PageData currentPage) { return View($"~/Views/{currentPage.GetOriginalType().Name}/Index.cshtml", currentPage); } }
public class LoadCustomDataAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { object currentPage; if (filterContext.ActionParameters.TryGetValue("currentPage", out currentPage)) { ServiceLocator.Current.GetInstance<ICustomPageLoaderService>().LoadCustomData(currentPage as PageData, filterContext.HttpContext.User); } base.OnActionExecuting(filterContext); } }
I kind of have the same problem as this person: http://stackoverflow.com/questions/29389926/why-is-the-icontentevents-loadedcontent-event-fired-multiple-times-for-a-page
I basicaly want to intercept whenever SitePage is passed to a controller method.
I tried using IContentLoader.LoadedContent, but if the method is fired about 20 times for each page request then I can't use it.
Can anybody outhere enligten me on the subject?
Here is my code: