Copied to clipboard

Flag this post as spam?

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


  • Anders Vestergaard 2 posts 72 karma points
    May 27, 2016 @ 11:46
    Anders Vestergaard
    0

    SurfaceController views, not found in views folder

    SurfaceController cannot find view in ~/Views/


    Question: Why can't my SurfaceController find the View in the Views folder?

        public class TestSurfaceController : Umbraco.Web.Mvc.SurfaceController
    {
    
        public ActionResult TestSurfaceController()
        {
            return View("Test");
        }
    
    }
    

    Sweet Candy:

    • My View Is called "Test" and exists in Views Folder
    • If I relocate "Test" to "TestSurface" or "Shared" folder everything is fine

    Origin to Frustration Candy

    Routing for locally declared controllers All locally declared controllers get routed to:

    /umbraco/surface/{controllername}/{action}/{id}

    They do not get routed via an MVC Area so any Views must exist in the following folders:

    ~/Views/{controllername}/ ~/Views/Shared/ ~/Views/

    Goal

    • I just want to have my view in ~/Views/, so I can edit the page in Umbraco - content node

    If Else Question
    Maybe there is a work around, eg
    How to Make Umbraco Content > Template show views in subfolder?

  • Marc Goodson 2126 posts 14217 karma points MVP 8x c-trib
    May 27, 2016 @ 17:11
    Marc Goodson
    1

    Hi Anders

    I might not be understanding correctly what you are aiming to do...

    but normally a surface controller sits kind of on the surface of a rendermvccontroller to handle a form post

    so you would likely return:

    RedirectToCurrentUmbracoPage() or CurrentUmbracoPage() - keeps the modelstate intact

    or one of the other helpers, once you have done something with the posted data.

    Alternatively you can create a child action on a surfacecontoller and render it's output within a template using

    @Html.Action("actionname","controllername")

    in this case your child action would return a partial view and you would create this in the /views/partials folder

    and then you could edit the html of the partial view via the back office in the settings/partial views tree

    regards

    marc

  • Anders Vestergaard 2 posts 72 karma points
    May 30, 2016 @ 07:58
    Anders Vestergaard
    0

    Hi Marc - High Five

    Thank you for replying back!

    So let me rephrase my situation.

    1. *Isn't it a fail in the Umbraco documentation that it says that the VIew can be in the ~/Views/?

    Source + Quote:

    Routing for locally declared controllers

    All locally declared controllers get routed to:

    /umbraco/surface/{controllername}/{action}/{id}

    They do not get routed via an MVC Area so any Views must exist in the following folders:

    ~/Views/{controllername}/ ~/Views/Shared/ ~/Views/

    2. I want to call a http request (Call a URL) and receive a View that can be seen in Umbraco.

    /Anders

  • Marc Goodson 2126 posts 14217 karma points MVP 8x c-trib
    Jun 04, 2016 @ 08:46
    Marc Goodson
    0

    Hi Anders

    (yes the documentation may be out of date)

    You can, because it's MVC always return a view with a specific path:

    eg

    return View("~/Views/myview.cshtml",model);
    

    If that would work for you ?

    But still not 100% on what you are trying to achieve, does the View need to inherit from UmbracoTemplate or similar, ie are you writing out Umbraco properties inside the view, or is it a totally seperate non Umbraco View, that you just want to have edited via the back office ?

    The other option is to use RouteHijacking: (https://our.umbraco.org/documentation/reference/routing/custom-controllers)

    Create a DocumentType for your request and note the alias, and create a page in Umbraco, based on that DocumentType.

    Now create a controller called (naming is important)

    public class DocTypeAliasController : RenderMvcController
    

    now all requests for the page based on this DocumentType are routed through this controller via an ActionResult called Index:

      public override ActionResult Index(RenderModel model)
        {
           // you can return your custom view here....
        }
    

    or another option would be to define a custom route:

    https://our.umbraco.org/documentation/reference/routing/custom-routes

    http://shazwazza.com/post/custom-mvc-routes-within-the-umbraco-pipeline/

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft