No właśnie w tym problem bo w RouteConfig mam takie coś:
Kopiuj
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { area = "Public", controller = "News", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Example.WebUI.Areas.Public.Controllers" }
);
}
Przy debugu jest wywoływany dobry kontroler ale już widok jest zły zwracany, chyba, że usunę widok z "głównego" projektu i zostaną tylko te w Areas to wtedy mam taki błąd:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/News/Index.aspx ~/Views/News/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx ~/Views/News/Index.cshtml ~/Views/News/Index.vbhtml ~/Views/Shared/Index.cshtml ~/Views/Shared/Index.vbhtml
Więc złe miejsce jest przeszukiwane.
Utworzyłem silnik widoku:
Kopiuj
public class CustomLocationViewEngine : RazorViewEngine
{
public CustomLocationViewEngine()
{
AreaViewLocationFormats = new string[]
{
"~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/Public/Views/{1}/{0}.cshtml"
};
}
}
oraz zmieniłem global.asax
protected void Application_Start()
Kopiuj
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new CustomLocationViewEngine());
}
Teraz błąd wygląda tak:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/News/Index.cshtml ~/Views/News/Index.vbhtml ~/Views/Shared/Index.cshtml ~/Views/Shared/Index.vbhtml
Edit://
Problem rozwiązany. Usunąłem te silniki widoków i RegisterRoutes wygląda tak:
Kopiuj
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { area = "Public", controller = "News", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Example.WebIU.Areas.Public.Controllers" }
);
}
Natomiast PublicAreaRegistration tak:
Kopiuj
public class PublicAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Public";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Public_default",
"{controller}/{action}/{id}",
new { controller = "News", action = "Index", id = UrlParameter.Optional }
);
}
}