Reputation: 2590
I want the default action method to be called in route.config
should be the action method of an area
. So I have done something like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
routes.MapRoute(
name: "Default",
url: "{culture}/{controller}/{action}/{id}",
defaults: new { culture = "en", controller = "LocationCon", action = "LocationIndex", id = UrlParameter.Optional },
namespaces: new[] { "Locator.Areas.LocationArea.Controllers" }
);
}
Here - LocationIndex
is the action name, LocationCon
is the controller and LocationArea
as area.
This is not working. Any help would be appreciated.
Upvotes: 0
Views: 162
Reputation: 24957
I think that No resource found
error originated from MVC view engine, where your view engine still using default parameters to find proper cshtml file even action methods executed successfully.
AFAIK, by default MVC view engine searching view files in Project/Views/ControllerName
and Project/Views/Shared
directory, which your Project/Culture/ControllerName
doesn't included.
You can configure custom view engine to search corresponding view files like example below:
using System.Web.Mvc;
public class ViewEngine : RazorViewEngine
{
public ViewEngine()
{
MasterLocationFormats = new[]
{
// your layout cshtml files here
};
ViewLocationFormats = new[]
{
// your view cshtml files here. {0} = action name, {1} = controller name
// example:
"~/Culture/{1}/{0}.cshtml"
};
PartialViewLocationFormats = ViewLocationFormats;
FileExtensions = new[]
{
"cshtml"
};
}
}
Hence, on Global.asax
file place your custom view engine on Application_Start
method:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
...
// other code here
...
ViewEngines.Engines.Add(new ViewEngine()); // add your custom view engine above
}
CMIIW.
Upvotes: 1