Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6112955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:48:13+00:00 2026-05-23T14:48:13+00:00

I have only tried this in single project areas. So if anyone tries this

  • 0

I have only tried this in single project areas. So if anyone tries this in a multi-project areas solution please let us know.

Area support was added to MVC2. However the views for your controllers have to be in your main Views folder. The solution I present here will allow you to keep your area specific views in each area. If your project is structured like below, with Blog being an area.

+ Areas          <-- folder
  + Blog         <-- folder
    + Views      <-- folder
      + Shared   <-- folder
      Index.aspx
      Create.aspx
      Edit.aspx
+ Content
+ Controllers
...
ViewEngine.cs

Add this code to the Application_Start method in Global.asax.cs. It will clear your current view engines and use our new ViewEngine instead.

// Area Aware View Engine
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new AreaViewEngine());

Then create a file named ViewEngine.cs and add the code below.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web.Mvc;

namespace MyNamespace
{

    public class AreaViewEngine : WebFormViewEngine
    {
        public AreaViewEngine()
        {
            // {0} = View name
            // {1} = Controller name

            // Master Page locations
            MasterLocationFormats = new[] { "~/Views/{1}/{0}.master"
                                          , "~/Views/Shared/{0}.master"
                                          };

            // View locations
            ViewLocationFormats = new[] { "~/Views/{1}/{0}.aspx"
                                        , "~/Views/{1}/{0}.ascx"
                                        , "~/Views/Shared/{0}.aspx"
                                        , "~/Views/Shared/{0}.ascx"
                                        , "~/Areas/{1}/Views/{0}.aspx"
                                        , "~/Areas/{1}/Views/{0}.ascx"
                                        , "~/Areas/{1}/Views/Shared/{0}.aspx"
                                        , "~/Areas/{1}/Views/Shared/{0}.ascx"
                                        };

            // Partial view locations
            PartialViewLocationFormats = ViewLocationFormats;

        }

        protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
        {
            return new WebFormView(partialPath, null);
        }

        protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
        {
            return new WebFormView(viewPath, masterPath);
        }

    }   // End Class AreaViewEngine

}       // End Namespace    

This will find and use the views you have created in your areas.

This is one possible solution that allows me to keep views in the specified area. Does anyone else have a different, better, enhanced solution?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:48:14+00:00Added an answer on May 23, 2026 at 2:48 pm

    This solution works well in Mvc2. It is not necessary in Mvc3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have only one button in showConfirmDialog . I tried this: int
I need to have a TreeView with only vertical scrollbar. I tried this but
I have tried : c(module_name). : but this only works from the shell, and
I have a problem with a single C# project in a solution of 21
I have this code: https://github.com/magicgoose/lwjgl-nifty-test-project When I render only GUI, it works like expected.
I have tried using the code below but it only display results in Chrome
I have tried the following MySQL update but it only sets the first field
I have only started learning Python recently. Let me explain what I am trying
I have some project where I have a single producer thread which writes events
I'm using NUnit (but have also tried this with VS testing) and I'm having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.