Project structure for when using MVC Areas

Posted by Community Admin on 04-Aug-2018 20:14

Project structure for when using MVC Areas

All Replies

Posted by Community Admin on 27-May-2015 00:00

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?

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

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
 

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

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?

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

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
 

Posted by Community Admin on 10-Sep-2015 00:00

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

Posted by Community Admin on 15-Sep-2015 00:00

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
 

Posted by Community Admin on 15-Sep-2015 00:00

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

Posted by Community Admin on 18-Sep-2015 00:00

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?

Posted by Community Admin on 18-Sep-2015 00:00

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

Best,
Daniel

Posted by Community Admin on 16-Nov-2016 00:00

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

Posted by Community Admin on 16-Nov-2016 00:00

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

Posted by Community Admin on 16-Nov-2016 00:00

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?

Posted by Community Admin on 16-Nov-2016 00:00

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

Best,
Daniel

Posted by Community Admin on 16-Nov-2016 00:00

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!

This thread is closed