Omid
Omid

Reputation: 321

ASP.NET MVC Razor cannot find views in area

URLs work correctly
Actions work correctly
the only problem is that the razor engine is just searching for view files in ~/Views and not in ~/Areas/Admin and I don't know why is that because it used to work fine
It works when I fill the return view type of the action by the exact path of its view but the absolute path for views is not working

Admin Area Directory

Here is one action for example but none of the actions in the admin area can call their views
Even _Logout which is a partial view ib Shared cannot be called by _Layout unless using the full path
Action in Controller:

        // GET: Admin/Login
        [Route("Admin/Login")]
        public ActionResult Login()
        {
            return View();
        }

Error:

The view 'Login' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Default/Login.aspx
~/Views/Default/Login.ascx
~/Views/Shared/Login.aspx
~/Views/Shared/Login.ascx
~/Views/Default/Login.cshtml
~/Views/Default/Login.vbhtml
~/Views/Shared/Login.cshtml
~/Views/Shared/Login.vbhtml

Upvotes: 1

Views: 1045

Answers (1)

Omid
Omid

Reputation: 321

Solved!
[RouteArea("Admin", AreaPrefix = "")] Was missing from top of my controller

Upvotes: 1

Related Questions