I request an action which is inside an area. Route is correct so debugger goes into the action. If I access RouteData property in the action, I see controller, action and area names (so area key is set). But during View rendering I get an exception telling that view can not be find (it searches only among root-level views, not inside area). But if I explicitly specify View name, it works.
So the question is how to make it work implicitly?
Update1 Here is a screenshot with RouteData in Watches in my project structure:
Update2 Here is the text of the exception:
The view 'Battles' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/AdminBattles/Battles.aspx ~/Views/AdminBattles/Battles.ascx ~/Views/Shared/Battles.aspx ~/Views/Shared/Battles.ascx ~/Views/AdminBattles/Battles.cshtml ~/Views/AdminBattles/Battles.vbhtml ~/Views/Shared/Battles.cshtml ~/Views/Shared/Battles.vbhtml
Sorry, it was my fault. I registered area routes calling context.Routes.MapRoute()
instead of context.MapRoute()
method.
Idsa,
You may find that a similar question that I had today (which I figured out) may help:
goin back to my 'routes' - issue with partialviews and areas??
basically, in your views web.config file(s), reference the namespaces that directly relate to either the root or the areas portions of the site.
worked for me in a very similar error scenario.
[edit] - re the custom viewengine. just add the following class to your Models folder (with your own custom paths of course):
using System.Linq;
using System.Web.Mvc;
namespace ABC.Web.Site.Areas.Administration.Models
{
public class ABCViewEngine : WebFormViewEngine
{
private static readonly string[] NewPartialViewFormats =
new[] {
"~/Areas/Administration/Views/Shared/Full/{0}.aspx",
"~/Areas/Administration/Views/Shared/Partial/{0}.ascx"
};
public ABCViewEngine()
{
base.PartialViewLocationFormats = base.PartialViewLocationFormats.Union(NewPartialViewFormats).ToArray();
}
}
}
then add the following to your global.asax (Application_Start()):
ViewEngines.Engines.Add(new ABCViewEngine());
good luck..
Have you created a folder with the same name as your controller (without the Controller bit) underneath Views and put your view in there?
So, not:
Areas
AreaName
Views
MyView.aspx
but...
Areas
AreaName
Views
ControllerNameWithoutControllerOnTheEnd
MyView.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With