Copied to clipboard

Flag this post as spam?

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


  • Graham Davis 110 posts 376 karma points
    Jun 01, 2018 @ 14:34
    Graham Davis
    0

    Plugin Development with route for html.partial

    I am developing a plugin in Version 7. How do I configure Umbraco so that this:

       @Html.Partial("~/App_Plugins/SiteData/Views/Shared/_dbButtons.cshtml")
    

    can be shortened to this:

       @Html.Partial("_dbButtons")
    
  • Marc Goodson 2126 posts 14217 karma points MVP 8x c-trib
    Jun 01, 2018 @ 23:36
    Marc Goodson
    100

    Hi Graham

    In MVC you can add new locations for searching for Views, by creating a new ViewEngine...

    ... that said...

    Umbraco already has a PluginViewEngine

    https://github.com/umbraco/Umbraco-CMS/blob/7ee510ed386495120666a78c61497f58ff05de8f/src/Umbraco.Web/Mvc/PluginViewEngine.cs

    which looks like to me is already searching in the location you are describing:

      AreaPartialViewLocationFormats = new[]
                {
                    //will be used when we have partial view and child action macros
                    string.Concat(SystemDirectories.AppPlugins, "/{2}/Views/Partials/{0}.cshtml"),
                    string.Concat(SystemDirectories.AppPlugins, "/{2}/Views/Partials/{0}.vbhtml"),
                    string.Concat(SystemDirectories.AppPlugins, "/{2}/Views/MacroPartials/{0}.cshtml"),
                    string.Concat(SystemDirectories.AppPlugins, "/{2}/Views/MacroPartials/{0}.vbhtml"),                    
                    //for partials                    
                    string.Concat(SystemDirectories.AppPlugins, "/{2}/Views/{1}/{0}.cshtml"),
                    string.Concat(SystemDirectories.AppPlugins, "/{2}/Views/{1}/{0}.vbhtml"),
                    string.Concat(SystemDirectories.AppPlugins, "/{2}/Views/Shared/{0}.cshtml"),
                    string.Concat(SystemDirectories.AppPlugins, "/{2}/Views/Shared/{0}.vbhtml")
                };
    

    so I'd expect your shortened version to work...

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft