0

When I run the website, I'm expecting the Home view to be displayed but its not finding the view. If i alter the code below, and remove the .mvc from ("{controller}.mvc/{action}" I get the base index view, not the Home view i wish to get from the Home Area.

What I noticed after I removed .mvc from the Route - The Home controller located inside Areas-Home-Controllers-HomeController is being found and executed, when the view gets returned and the AreaViewEngine takes ahold of it, it doesn't see the Areas so it returns base index view... Any clue what could be causing this!?

I have the following RegisterRoutes

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapAreas("{controller}/{action}/{id}",
        "ProjectNamespace.Web",
        new[] { "Home" });

    routes.MapRootArea("{controller}.mvc/{action}",
        "ProjectNamespace.Web",
        new { controller = "Home", action = "Index" });
}

Here is ViewFind located in AreaViewEngine.cs:

   public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
        {
            ViewEngineResult areaResult = null;

            if (controllerContext.RouteData.Values.ContainsKey("area")) 
            {
                string areaViewName = FormatViewName(controllerContext, viewName);
                areaResult = base.FindView(controllerContext, areaViewName, masterName, useCache);
                if (areaResult != null && areaResult.View != null) 
                {
                    return areaResult;
                }
                string sharedAreaViewName = FormatSharedViewName(controllerContext, viewName);
                areaResult = base.FindView(controllerContext, sharedAreaViewName, masterName, useCache);
                if (areaResult != null && areaResult.View != null) 
                {
                    return areaResult;
                }
            }
            return base.FindView(controllerContext, viewName, masterName, useCache);
        }

The BaseController which is located in the default Controllers root directory:

public abstract class BaseController : Controller
{
    public virtual ActionResult Index()
    {
        return View();
    }
}

Here is the Home controller located in Areas-Home-Controllers:

public class HomeController : BaseController
{
    public HomeController()
    {
    }

    public override ActionResult Index()
    {           
        HomeDetailsViewModel model = new HomeDetailsViewModel();
        model.User = "testing username"
        return View("Index", model);
    }
 }

Finally, screenshot of the Solutions Explorer:

enter image description here

Dayan
  • 7,634
  • 11
  • 49
  • 76

1 Answers1

0

for an area you have to specify it. try this

return RedirectToAction("Index", "Home", new { area = "Home" });
Matt Bodily
  • 6,403
  • 4
  • 29
  • 48
  • Its not working for me, "Firefox has detected that the server is redirecting the request for this address in a way that will never complete" - I should have mentioned that `HomeController` also implements `IDisposable`. – Dayan Mar 04 '14 at 21:41
  • 1
    I just searched and my answer should be working for you http://stackoverflow.com/questions/1391887/redirecttoaction-between-areas. Home is a reserved word that mvc uses as a default. Since it is in an area I would recommend changing that name to something else. See if that helps – Matt Bodily Mar 04 '14 at 22:02