Remove Default MVC .vbhtml Paths - Implement Custom ViewEngi

Posted by Community Admin on 05-Aug-2018 20:44

Remove Default MVC .vbhtml Paths - Implement Custom ViewEngine

All Replies

Posted by Community Admin on 12-Jun-2015 00:00

Since .vbhtml is not a supported extension in Sitefinity (at least according to the documentation here: http://docs.sitefinity.com/for-developers-how-does-sitefinity-use-asp-net-mvc only .cshtml is supported), Telerik should probably inherit the RazorViewEngine or the BuildManagerViewEngine and trim down the list of paths (and supported file types in the IViewEngine.FileExtensions property) to reduce the number of file system locations needing to be checked when a view is first looked up in FindView(...) or FindPartialView(...) before the view location is cached.

Also, partial view lookup out of the box does not work with Sitefinity. If you take the valid default paths:
"~/Views/1/0.cshtml",
"~/Views/Shared/0.cshtml"

and change them to:
"~/Mvc/Views/1/0.cshtml",
"~/Mvc/Views/Shared/0.cshtml"

then the partial view lookup works as expected. You'd fix both of these issues by not using the default RazorViewEngine implementation.

 

Here's what I did. We aren't using areas, so I wiped those, but you'd just want to remove the default .vbhtml paths in th​e area path sets for your purposes. This might help:

    using System.Web.Mvc;

    public class MyViewEngine : RazorViewEngine
    
        private static string[] EmptyArray = new string[] ;

        private static string[] SitefinityFileExtensions = new string[]
            
                "cshtml"
            ;

        private static string[] SitefinityMasterLocationFormats = new string[]
            
                "~/Views/1/0.cshtml",
                "~/Views/Shared/0.cshtml"
            ;

        // The first two paths are only here for now to support EditorTemplate lookups at the root - Sitefinity bug work around
        private static string[] SitefinityPartialViewLocationFormats = new string[]
            
                "~/Views/1/0.cshtml",
                "~/Views/Shared/0.cshtml",
                "~/Mvc/Views/1/0.cshtml",
                "~/Mvc/Views/Shared/0.cshtml"
            ;

        private static string[] SitefinityViewLocationFormats = new string[]
            
                "~/Views/1/0.cshtml",
                "~/Views/Shared/0.cshtml"
            ;

        public MyViewEngine()
        
            // Remove area support to reduce view lookup paths (improves performance)
            base.AreaMasterLocationFormats = EmptyArray;
            base.AreaPartialViewLocationFormats = EmptyArray;
            base.AreaViewLocationFormats = EmptyArray;

            base.MasterLocationFormats = SitefinityMasterLocationFormats;
            base.PartialViewLocationFormats = SitefinityPartialViewLocationFormats;
            base.ViewLocationFormats = SitefinityViewLocationFormats;

            // Sitefinity MVC only supports C# - remove VB support
            base.FileExtensions = SitefinityFileExtensions;
        
    

and then I have this registered in Global.asax.cs Application_Start:

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new WebFormViewEngine());
ViewEngines.Engines.Add(new MyViewEngine());

Posted by Community Admin on 09-Jul-2015 00:00
Hi,

More information about this issue could be found in the discussions listed below:
http://www.sitefinity.com/developer-network/forums/bugs-issues-/mvc-partial-view-lookup-does-not-work-ootb
http://www.sitefinity.com/developer-network/forums/bugs-issues-/rendering-a-child-action-using-html-renderaction-is-broken#0oLSnPjxA0yioaUkTUhZMQ

Regards,
Svetoslav Manchev
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 
Posted by Community Admin on 13-Jul-2015 00:00

I think that the second issue you were trying to link to is the wrong link, as that is an unrelated bug that I also found. I think this is the second link you were looking for:

 MVC EditorTemplates do not work as expected

Posted by Community Admin on 17-Jul-2015 00:00
Hi Richard,

You are correct, thank you for the clarification.

Regards,
Svetoslav Manchev
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 
This thread is closed