我希望在中调用默认操作方法应该是
route.config
的操作方法。所以我做了类似的事情:
area
此处 - 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" }
);
}
是操作名称,LocationIndex
是控制器,LocationCon
是区域。
这不起作用。任何帮助将不胜感激。
答案 0 :(得分:1)
我认为No resource found
错误源自MVC视图引擎,其中您的视图引擎仍然使用默认参数来查找正确的cshtml文件,甚至动作方法也成功执行。
AFAIK,默认情况下MVC视图引擎搜索Project/Views/ControllerName
和Project/Views/Shared
目录中的Project/Culture/ControllerName
未包含的视图文件。
您可以配置自定义视图引擎以搜索相应的视图文件,如下例所示:
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"
};
}
}
因此,在Global.asax
文件上将您的自定义视图引擎置于Application_Start
方法:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
...
// other code here
...
ViewEngines.Engines.Add(new ViewEngine()); // add your custom view engine above
}
CMIIW。