Accessing Linq Values in ViewData
- by Jemes
I'm having trouble accessing the id, area and theme values in my ViewData.
They are being set in my action filter but when I get to the Site.Master I don't have access to them.
Any help or advice would be great.
ActionFilter
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    int SectionID = Convert.ToInt32(filterContext.RouteData.Values["Section_ID"]);
    int CourseID = Convert.ToInt32(filterContext.RouteData.Values["Course_ID"]);
        if (CourseID == 0)
        {
            filterContext.Controller.ViewData["Styles"] = (from m in _dataContext.Styles where m.Area_ID == SectionID select new {theme = m.Area_FolderName }).ToList();
        }
        else
        {
            filterContext.Controller.ViewData["Styles"] = (from m in _dataContext.Styles where m.Course_ID == CourseID select new { theme = m.Course_FolderName }).ToList();
        }
    }
}
Site.Master
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %
<%@ Import Namespace="Website.Models" %
<%       
    foreach (var c in (IEnumerable<Styles>)ViewData["Styles"])
   {
    Response.Write(c.Theme);
}%>