I'm baffled. My site randomly throws the following error:
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: The partial view '/SiteUserMenu' could not be found. The following locations were searched:
/SiteUserMenu
at System.Web.Mvc.HtmlHelper.FindPartialView(ViewContext viewContext, String partialViewName, ViewEngineCollection viewEngineCollection)
at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, ViewEngineCollection viewEngineCollection)
at System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName)
at ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer)
Most of the time, the site runs fine... sometimes it throws the above error, which makes no sense to me. If the partial view wasn't found, why would it not be able to find it sometimes?
The partial view is saved in a folder named "en" under the Shared folder (inside of the views folder). Here's how I render the view:
<% Html.RenderPartial(ViewData["lang"] + "/SiteUserMenu"); %>
ViewData["lang"] is set in my base controller, in the OnActionExecuting action, like so:
var l = (RouteData.Values["language"] != null) ? RouteData.Values["language"].ToString() : string.Empty;
if (string.IsNullOrEmpty(l))
l = "en";
if (l.Contains("en"))
{
IsEnglish = true;
l = "en";
}
else
l = "ja";
ViewData["lang"] = l.ToLower();
Language = l.ToLower();
Language and IsEnglish are properties of the base controller. The whole site uses them to maintain language selection and to make appropriate choices based on language. If language is not set, it will be set to "en". So ViewData["lang"] should always be available to my views.
Any reason why a partial view couldn't be found somtimes, while most of the time (I'm talking 90% of the time) it works fine?