Repository code:
public IQueryable<Bundle> getAllCustomBundlesByCompanyID(int companyID)
{
return from companyBundle in db.CompanyBundles
join bundle in db.Bundles on companyBundle.BundleID equals bundle.BundleID
where companyBundle.CompanyID == companyID && bundle.CompanyID == companyID
orderby bundle.BundleName ascending
select bundle;
}
Controller code:
ViewData["OurCategories"] = bundleRepository.getAllCustomBundlesByCompanyID(CompanyID);
View code:
<ul class="SmallCats">
<%if(ViewData["OurCategories"] != null){ %>
<%List<KODmvc.Models.Bundle> ourCategories = ViewData["OurCategories"] as List<KODmvc.Models.Bundle>; %>
<%foreach(KODmvc.Models.Bundle b in ourCategories) { %>
<li><a href="<%=b.BundleID%>">
<img src="/Content/images/bundleicons/<%=b.BundleIcon %>" />
<%=b.BundleName %></a>
</li>
<%} %>
<%} else { %>
There are no custom categories.
<%} %>
</ul>
ERROR:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 38: <%if(ViewData["OurCategories"] != null){ %>
Line 39: <%List<KODmvc.Models.Bundle> ourCategories = ViewData["OurCategories"] as List<KODmvc.Models.Bundle>; %>
Line 40: <%foreach(KODmvc.Models.Bundle b in ourCategories) { %>
Line 41: <li><a href="<%=b.BundleID%>">
Line 42: <img src="/Content/images/bundleicons/<%=b.BundleIcon %>" />
Source File: e:\Bancroft Archive\PanamaTrunk\Views\Asset\AdminDashboard.aspx Line: 40
But I am checking to make sure the ViewData is not null before letting it in, what on earth??