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

Forums / Developing with Sitefinity / Project structure for when using MVC Areas

Project structure for when using MVC Areas

14 posts, 0 answered
  1. David
    David avatar
    99 posts
    Registered:
    06 Sep 2012
    27 May 2015
    Link to this post

    The Sitefinity Documentation say, "All MVC artifacts in Sitefinity should be stored under the Mvc folder". Does this apply when using MVC Areas? I'm at the point where I am starting to believe there is something about MVC that requires the Area folder to be a root folder of the web application. Can you please either post or provide a link to a sample that uses Areas inside the Mvc folder?

  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    05 Dec 2016
    01 Jun 2015
    Link to this post
    Hello David,

    You may refer to the below documentation article and review the sample for the bug tracker application where we use areas:

    Create a bug tracker application

    Regards,
    Sabrie Nedzhip
    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. David
    David avatar
    99 posts
    Registered:
    06 Sep 2012
    02 Jun 2015
    Link to this post

    The problem I have with the BugTracker application is that it does not comply with another documentation article that states,  "All MVC artifacts in Sitefinity should be stored under the Mvc folder".

    Questions:
    1. Is there something about the way Sitefinity is programmed that would make my code run differently if I were to put my MVC artifacts in a folder named something other than "Mvc". For instance, what if I were to use my company name instead of "Mvc" for the folder name? 

    My concerns are:

    1. ​The BugTracker application may have been written prior to Sitefinity requiring "all MVC artifacts be under Mvc folder."

    2. Eventhough the BugTracker application works outside the Mvc folder, a larger more complex application may not.

    Can you please address my questions and concerns?

  4. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    05 Dec 2016
    05 Jun 2015
    Link to this post
    Hello David,

    You are right that when using MVC in Sitefinity, the controllers, views and models need to be placed in the MVC folder which is in the root of your project. 

    In order to use Areas for widgets, you would need to inherit the ControllerActionInvoker and add your custom logic of handling the areas by overriding the InitializeRouteParameters() method. Here is a sample code which you can use:


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Sitefinity.Mvc;
    using Telerik.Sitefinity.Mvc.Proxy;
    using Telerik.Sitefinity.Web;
      
    namespace SitefinityWebApp
    {
        public class MvcControllerActionInvoker : ControllerActionInvoker
        {
            protected override void InitializeRouteParameters(MvcProxyBase proxyControl)
            {
                base.InitializeRouteParameters(proxyControl);
                var areaName = proxyControl.Controller.GetType().FullName.Split('.')[2];
                if (areaName != null)
                proxyControl.Controller.RouteData.DataTokens.Add("area", areaName);
                  
            }
        }
    }

    As you can see from the above sample you can get the area from the full name where the first position will be  SitefinityWebApp, then Areas and the name of the area.

    Here is how you can register the custom type in the Global.asax file:

    using System;
    using System.Linq;
    using Telerik.Microsoft.Practices.Unity;
    using Telerik.Sitefinity.Abstractions;
    using Telerik.Sitefinity.Mvc;
      
    namespace SitefinityWebApp
    {
        public class Global : System.Web.HttpApplication
        {
      
            protected void Application_Start(object sender, EventArgs e)
            {
                Bootstrapper.Initialized += Bootstrapper_Initialized;
            }
      
            void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
            {
                if (e.CommandName=="Bootstrapped")
                {
                    ObjectFactory.Container.RegisterType<IControllerActionInvoker, MvcControllerActionInvoker>();
                }
            }

    Regards,
    Sabrie Nedzhip
    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
     
  5. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    10 Sep 2015 in reply to Sabrie Nedzhip
    Link to this post

    Does this still apply for Feather Widgets within Sitefinity 8.1?

    I'd like to use Areas, but I'm not sure how to configure this right. Should Areas be placed under the root, or under /Mvc ? Also, do we need to use the MvcControllerInvoker, or is it enough to use the AreaRegistration class?

    Anyway, it doesn't work :(

    Best,
    Daniel

  6. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    05 Dec 2016
    15 Sep 2015
    Link to this post
    Hi Daniel,

    There should not be any issues registering the custom area following the approach from my last reply. We have tested this approach in Sitefinity 8 project and were able to register the custom area.

    Regards,
    Sabrie Nedzhip
    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
     
  7. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    15 Sep 2015 in reply to Sabrie Nedzhip
    Link to this post

    Hi Sabri,

    I guess when using Feather, we need to inherit from the FeatherActionInvoker instead of the ControllerActionInvoker?

    What is not clear is where to place the Area folder: inside the MVC folder or under the root folder?

    Best,
    Daniel

  8. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    18 Sep 2015
    Link to this post

    I created a new ActionInvoker based on the FeatherActionInvoker, and now it seems to work fine. I can create areas which contains Feather Widgets. Great!

    A problem that occurs now is that when I create new designer windows for my Feather widgets, they are not picked up by the widget. So it only works if I place the designer and the scripts under the /Mvc folder.

    How can I make sure that designers and scripts are loaded when they are also placed under the Areas folder?

  9. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    18 Sep 2015 in reply to Daniel Plomp
    Link to this post

    Should I do something with the DesignerUrlAttribute to make this work?

    Best,
    Daniel

  10. Eduardo
    Eduardo avatar
    3 posts
    Registered:
    10 Dec 2013
    16 Nov in reply to Daniel Plomp
    Link to this post

    Hi Daniel, did you solved all this problems?

    We'd like to use Areas but I'd like to make sure that this is trouble-free before trying :S

  11. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    16 Nov in reply to Eduardo
    Link to this post

    No, unfortunately I do not have a solution for this. However, it works fine as how I described it.

    Maybe if the widgets and areas are in a separate project. I didn't try that.

    Best,
    Daniel

  12. Eduardo
    Eduardo avatar
    3 posts
    Registered:
    10 Dec 2013
    16 Nov in reply to Daniel Plomp
    Link to this post

    Thanks! We have a separate project for custom MVC form controls, but I'm trying to avoid having different projects in this particular case, as cross-references already arise.

    Areas would be enough for us, but of course form fields require scripts and designers and having those folders spread inside the area folder and also in the main Mvc folder is not ideal.

    Do you have any advice in this case?

  13. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    16 Nov
    Link to this post

    Are you also using Feather in this project? That might be an option to isolate different components?

    Best,
    Daniel

  14. Eduardo
    Eduardo avatar
    3 posts
    Registered:
    10 Dec 2013
    16 Nov in reply to Daniel Plomp
    Link to this post

    Yes, in fact the MVC form fields are Feather widgets, but they still have to go inside the main Mvc folder.

    I've gave it a second thought and keeping it in a separate project seems to be the best option for us.

    Thanks!

14 posts, 0 answered