Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mário Nunes 7 posts 87 karma points
    Jul 15, 2018 @ 16:33
    Mário Nunes
    0

    Is it possible to load a View without setting the Template for the Document Type?

    Hello,

    Weird question!

    Is it possible to load a view without setting the template on the document type?

    If the template is not set, it always goes to 404 page and never enters the controller.

    I'm doing this because I don't want that specific view on the backoffice.

    Thanks!

  • Rihab 76 posts 288 karma points
    18 days ago
    Rihab
    0

    Did you find a way yo do that? I'm facing the same problem

  • Mário Nunes 7 posts 87 karma points
    1 week ago
    Mário Nunes
    0

    Hey, what I ended up doing was registering a controller at runtime, like this:

    RouteTable.Routes.MapRoute(
               "RouteName",
               "route",
               new { controller = "ControllerName", action = "ActionName" });
    

    Then on the controller:

     public ActionResult ActionName()
        {
            BaseModel model = ... (here I just got my homepage IPublishedContent) since the model didn't matter, just needed it for the base layout;
    
            return View("~/path/to/view.cshtml", model);
        }
    

    To note, I did all this on a different .csproj aside the main project, as an extensible plugin.

Please Sign in or register to post replies

Write your reply to:

Draft