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

Forums / Developing with Sitefinity / Adding own ViewEngine breaks backend

Adding own ViewEngine breaks backend

3 posts, 0 answered
  1. Christian
    Christian avatar
    5 posts
    Registered:
    13 Sep 2013
    24 Sep 2013
    Link to this post
    Hi,
    I implemented my own ViewEngine(inherited from RazorViewEngine od course)
    I needed to do that so I can use the _viewStart/Layout.cshtml mechanism.

    In global.asax.cs I added the Engine
    protected void Application_Start(object sender, EventArgs e)
            {

                Telerik.Sitefinity.Abstractions.Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(Bootstrapper_Initialized);

                Telerik.Sitefinity.Abstractions.Bootstrapper.MVC.MapRoute(
                   "AjaxCall", // Route name
                   "ajax/{controller}/{action}/{id}", // URL with parameters
                   new { controller = "Hausrat", action = "Index", id = UrlParameter.Optional }
               );

                ClientDataTypeModelValidatorProvider.ResourceClassKey = "ErrorDateTypeMessages";
                DefaultModelBinder.ResourceClassKey = "ErrorDateTypeMessages";



                //PowerTools.Instance
                //        .RootTemplates
                //        .RegisterMvcTemplateResolver<CustomMvcTemplateResolver>();
                

                // register bundles
                BundleConfig.RegisterBundles(BundleTable.Bundles);
            }

            void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
            {

                if (e.CommandName == "RegisterRoutes")
                {
                    RegisterRoutes(RouteTable.Routes);
                }

                if (e.CommandName == "Bootstrapped")
                {
                    ViewEngines.Engines.Add(new XitasoSiteFinityViewEngine()); <--
                }
            }

    But after that I broke the edit content backend action.
    if i navigate to {pagename}/Action/Edit I get redirected to the normal view of the page localhost/{pagename}

    Any idea how to prevent this behavior?

    Regards,

    Christian
  2. David C
    David C avatar
    33 posts
    Registered:
    02 Dec 2015
    25 Sep 2013
    Link to this post
    Hello,

    Can you give us an idea of what you are trying to ultimately accomplish? There might be an easier way to do this, but we want to make sure we understand your requirements first.

    Regards,
    David C
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. Christian
    Christian avatar
    5 posts
    Registered:
    13 Sep 2013
    26 Sep 2013 in reply to David C
    Link to this post
    Hi there,

    was my fault.
    i missed a RedirectToAction in the Index() Action.
    Now it works.

    The idea behind this is to integrate an existing MVC application as widgets.
    So i set all the JavaScript and Css paths in the _Layout.cshtml, which is is set by _viewStart.cshtml.
    The hole process is triggert by my own ViewEngine:
    protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
                {
                    var newViewEngine = new RazorView(
                        controllerContext,
                        viewPath,
                        masterPath,
                        true, //<--- this drives whether to use _ViewStart pages.  It was set to false
                        FileExtensions,
                        ViewPageActivator
                    );

                    return newViewEngine;
                }


    Regards,

    Christian
3 posts, 0 answered