+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / MVC EditorTemplates do not work as expected

MVC EditorTemplates do not work as expected

4 posts, 0 answered
  1. RJ Cuthbertson
    RJ Cuthbertson avatar
    41 posts
    Registered:
    01 Jun 2015
    12 Jun 2015
    Link to this post

    Out of the box, EditorTemplates (and presumably DisplayTemplates as well) do not work as expected.

     

    EditorTemplates at /Mvc/Views/Shared/EditorTemplates are not found by the RazorViewEngine. Instead, they will work if you put them in the standard MVC foldering structure at /Views/Shared/EditorTemplates.

     

    Normally you would fix this by fixing the view lookup paths in an inherited view engine, however adding the paths:

     "~/Mvc/Views/{1}/{0}.cshtml",
     "~/Mvc/Views/Shared/{0}.cshtml"

     to the set of paths in the ViewLocationFormats property of the view engine causes a number of NullReferenceExceptions when a page is rendered:

     

    06/12/2015 16:14:24
    Type : System.NullReferenceException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    Message : Object reference not set to an instance of an object.
    Source : Telerik.Sitefinity
    Help link :
    Data : System.Collections.ListDictionaryInternal
    TargetSite : System.Web.Caching.CacheDependency GetCacheDependency(System.String, System.Collections.IEnumerable, System.DateTime)
    HResult : -2147467261
    Stack Trace :    at Telerik.Sitefinity.Abstractions.VirtualPath.SitefinityVirtualPathProvider.GetCacheDependency(String virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
       at Telerik.Sitefinity.Frontend.Mvc.Infrastructure.Controllers.Attributes.CacheDependentAttribute.GetCacheDependency(String virtualPath)
       at Telerik.Sitefinity.Frontend.Mvc.Infrastructure.Controllers.Attributes.CacheDependentAttribute.OnResultExecuted(ResultExecutedContext filterContext)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
       at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
       at Telerik.Sitefinity.Mvc.ControllerWrapper.Execute()
       at Telerik.Sitefinity.Mvc.ControllerActionInvoker.ExecuteController(MvcProxyBase proxyControl)
       at Telerik.Sitefinity.Frontend.Mvc.Infrastructure.Routing.DynamicUrlParamActionInvoker.ExecuteController(MvcProxyBase proxyControl)

     

    For now I can put the EditorTemplates in the Views folder at the root, but this is less than ideal. You should also have the ability to define specific EditorTemplates scoped to a controller specific view folder instead of just the shared folder, though this won't work as is.

  2. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    29 Nov 2016
    17 Jun 2015
    Link to this post
    Hello  Richard,

    This is the expected behaviour for the shared folder and additional sub folder. Your approach is the correct one.

    More information is available in that discussion.


    I hope this helps.

    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
     
  3. RJ Cuthbertson
    RJ Cuthbertson avatar
    41 posts
    Registered:
    01 Jun 2015
    17 Jun 2015
    Link to this post

    No, this isn't the expected behavior.

     

    If you read the original post again you'll see that EditorTemplate lookups do not work under the Sitefinity MVC foldering structure. If you put an EditorTemplate in /Mvc/Views/{controller}/EditorTemplates/ or /Mvc/Views/Shared/EditorTemplates/ they will never be found. Adding the additional view lookup paths for these folders breaks the default view lookup because the paths defined in the view engine are of the format "~/Views/{1}/{0}.cshtml" and "~/Views/Shared{0}.cshtml" without the Sitefinity Mvc folder prefixing the path. That means that somewhere in Sitefinity (VirtualPathProvider?) the path lookup is being re-written for View lookups, but it isn't happening when EditorTemplates are looked up. Adding the additional view lookup paths with the "~/Mvc/..." format conflicts with the default paths and results in the exception message above.

     

    In order for all of the MVC files to exist in the same place - in the /Mvc/ folder in the project as expressed in the documentation, rather than at the root of the project - this issue needs to be resolved by Telerik.

     

    That StackOverflow post that you referenced explains how to add your own paths to an inherited view engine for partial view lookup. It does not resolve the problem of Sitefinity throwing an exception when you try to fix this issue in the manner described.

  4. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    29 Nov 2016
    24 Jun 2015
    Link to this post
    Hi Richard,

    I already answer you in the other thread here.

    In case of any additional comments/questions, you can post them there.

    Thanks in advance.

    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
     
4 posts, 0 answered