Giter VIP home page Giter VIP logo

Comments (3)

jbogard avatar jbogard commented on July 29, 2024

You'd have to fix up the controller convention to instantiate the right controller.

Areas in MVC are kinda broken though, they were bolted on later so they're a bit funny to get to work outside of the default scenario.

from contosouniversity.

kengineer avatar kengineer commented on July 29, 2024

Thanks. I figured out that I need to modify the ControllerFactory, but figuring out the routing for the Areas is where I'm currently stuck, albeit, I haven't spent too much time at it yet. When I have a little more time, I'll take another crack at it.

from contosouniversity.

kengineer avatar kengineer commented on July 29, 2024

I got this working. I adding the following area location formats to the FeatureViewLocationRazorViewEngine class constructor

this.AreaViewLocationFormats =
this.AreaMasterLocationFormats =
this.AreaPartialViewLocationFormats = new[]
{
    "~/Areas/{2}/Features/{1}/{0}.cshtml",
    "~/Areas/{2}/Features/{1}/{0}.vbhtml",
    "~/Areas/{2}/Features/Shared/{0}.cshtml",
    "~/Areas/{2}/Features/Shared/{0}.vbhtml",
};

and modified the ControllerFactory.GetControllerType method like so

protected override Type GetControllerType(RequestContext requestContext, string controllerName)
{
    var tokens = requestContext.RouteData.DataTokens;
    var areaName = tokens["area"] as string;
    var areaNamespace = !String.IsNullOrEmpty(areaName) ? "Areas." + areaName + "." : String.Empty;

    var controllerTypeTemplate = "ContosoUniversity.{1}Features.{0}.UiController";
    var controllerType = String.Format(controllerTypeTemplate, controllerName, areaNamespace);

    return typeof(ControllerFactory).Assembly.GetType(controllerType);
}

No change was needed for the Area Registration class, which was a pleasant surprise.

from contosouniversity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.