Copied to clipboard

Flag this post as spam?

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


  • Angie Winterbottom 5 posts 26 karma points
    May 07, 2014 @ 12:18
    Angie Winterbottom
    0

    Partials from custom controller

    I have a site which contains a form, so I built a controller for it which renders a "Success" template on successful postback.

    This template sits under /Views/JobAdvert/Success.cshtml

    So I got it to use "../Master.cshtml" as the layout. It inherits UmbracoTemplatePage.

    The partials in the Master are not looking in the "Partials" folder. Am I missing something? I want to piggyback off the normal Umbraco view paths.

    How I'm calling the partial:

    @Html.Partial("_top-nav")

    The error message:

    The partial view '_top-nav' was not found or no view engine supports the searched locations. The following locations were searched:
    ~/Views/JobAdvert/_top-nav.aspx
    ~/Views/JobAdvert/_top-nav.ascx
    ~/Views/Shared/_top-nav.aspx
    ~/Views/Shared/_top-nav.ascx
    ~/Views/JobAdvert/_top-nav.cshtml
    ~/Views/JobAdvert/_top-nav.vbhtml
    ~/Views/Shared/_top-nav.cshtml
    ~/Views/Shared/_top-nav.vbhtml

    EDIT: Alternatively, I think I could just move the site's partials to the Shared folder; other than them not being editable from with the admin suite, do you think that would be a problem?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 07, 2014 @ 13:08
    Jan Skovgaard
    0

    Hi Angie and welcome to our :)

    Did you create this "top-nav" of yours as a partial view macro in the developer section of Umbraco? If not that's probably where you go wrong.

    Maybe it could also be that the underscore is not allowed? Perhaps try renaming to "top-nav" instead. And also see if you can use @UmbracoRenderMacro("top-nav")

    Perhaps it would be a good idea for you to read the documenation on how to build a basic site in order to get your feet wet an learn a bit about best practices etc.

    Hope this helps.

    /Jan

  • Angie Winterbottom 5 posts 26 karma points
    May 07, 2014 @ 14:51
    Angie Winterbottom
    0

    Hi Jan!

    This is actually my third commercial Umbraco site - I've been using Umbraco since version 4. I just didn't sign up to the forums until now. :)

    The underscore is fine. The use of a partial is fine. These exact same navigation partials have been working solidly throughout the rest of the site, the controller / view engine is just not looking for the partials in the "Partials" folder when I use it in a custom controller.

    If I deliberately misplace the partial template on a normal page, which isn't going through my custom controller, it gives me a different list of places it looks for the partial:

     

    The partial view 'top-nav' was not found or no view engine supports the searched locations. The following locations were searched:
    ~/Views/RenderMvc/top-nav.aspx
    ~/Views/RenderMvc/top-nav.ascx
    ~/Views/Shared/top-nav.aspx
    ~/Views/Shared/top-nav.ascx
    ~/Views/RenderMvc/top-nav.cshtml
    ~/Views/RenderMvc/top-nav.vbhtml
    ~/Views/Shared/top-nav.cshtml
    ~/Views/Shared/top-nav.vbhtml
    ~/Views/Partials/top-nav.cshtml
    ~/Views/MacroPartials/top-nav.cshtml
    ~/Views/top-nav.cshtml


    It's that list of view engine paths I want my custom controller to use, I just need to find out what is missing. My controller is using RenderMvcController as its base controller, and the master page inherits UmbracoTemplatePage, so I thought that would be enough, but it's not.

    I got my info on custom controllers from here: http://our.umbraco.org/documentation/Reference/Mvc/custom-controllers 

    EDIT: I found that it will load the partial from the template through a custom controller if I use the full path:

    @Html.Partial("~/Views/Partials/_top-nav.cshtml")

    Yay!

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 07, 2014 @ 15:43
    Jan Skovgaard
    0

    Hi Angie

    Ah ok, so you're pretty seasoned already - that's good :)

    And glad you managed to figure out what went wrong - Thanks for sharing.

    Cheers, Jan

Please Sign in or register to post replies

Write your reply to:

Draft