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

  • Home
  • SEARCH
  • 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 5847043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:39:45+00:00 2026-05-22T12:39:45+00:00

i am going Nuts, i am using MVCContrib, to create pluggable site using Portable

  • 0

i am going Nuts,
i am using MVCContrib, to create pluggable site using Portable Areas, and everything is working well so far, except that when i started using MVC Templates, what is happening is if i put the The templates in the respective folder of the View it works, examples

HostApplication/Views/Home/DisplayTemplates/FirstName.cshtml
HostApplication/Areas/PortableArea_Blog/Views/Home/DisplayTemplates/Auther.cshtml

but what i want really is the ability to create common templates Set and utilize it from either Host Application or Portable Area, so to do that i created a new Portable Area Called DisplayTemplates(to utilize MVCContrib Ability to compile Views), here is the portable Area structure

DisplayTemplates
|-Views
  |-CommentTemplate.cshtml

now in my host Application i have created a Test Model and added UIHint Attribute

public class HostModel
    {


        [UIHint("~/Areas/DisplayTemplates/Comment.cshtml")]
        public string Name { get; set; }
    }

but it is not working, so i thought it has something to do with Partial Views Location so i created a CustomView Engine to find Partial Views in that Location and registerd it in Global.asax, here is a short idea about so i wont bore you with full code

public class AreaViewEngine : RazorViewEngine
    {
        public AreaViewEngine()
        {

            // {0} = View name
            // {1} = Controller name

            // View locations
            ViewLocationFormats = new[]
                                      {
                                          "~/Areas/DisplayTemplates/{0}.cshtml"

                                      };

            PartialViewLocationFormats = ViewLocationFormats;

            AreaPartialViewLocationFormats = ViewLocationFormats;
        }

        protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
        {
            return new RazorView(controllerContext, partialPath, null, true, new[] { "cshtml" });
        }

        protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
        {
            return new RazorView(controllerContext, viewPath, masterPath, true, new[] { "cshtml" });
        }




    }

what is even more weird, is that it seems that that UIHint with Explicit location to Display Template, does not work, here is an example

public class HostModel
    {
        //this works
        [UIHint("FirstName")]
        //this does not work
        [UIHint("~/Views/Home/DisplayTemplates/FirstName.cshtml")]
        public string Name { get; set; }
    }

and yes

FirstName.cshtml is in HostApplication/Views/Home/DisplayTemplates/FirstName.cshtml

again sorry for the long post, but i gave up on finding a solution, so any help would be totally appreciated.

  • 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-22T12:39:46+00:00Added an answer on May 22, 2026 at 12:39 pm

    Danny is correct. The Templates are found the same way that Partial Views are found.

    By default the WebFormViewEngine and RazorViewEngine are going to search the following locations for a template.

    For display templates:

    ~/Views/{controller}/DisplayTemplates
    ~/Views/Shared/DisplayTemplates

    For editor templates:

    ~/Views/{controller}/EditorTemplates
    ~/Views/Shared/EditorTemplates

    I think the name of the sub-directories (i.e., “DisplayTemplates” and “EditorTemplates”) are hard-coded into MVC somewhere (I know it’s open source and I could find it, but I’m not going to).

    I think the easiest way to change the location somewhat is to override the ViewEngine. My custom ViewEngine is pretty complicated at this point, but I suspect you could get away with the following.

    Let’s say you want your templates to be in ~/Views/Templates.

    Create a class that inherits from the view engine you’re using now (probably WebFormViewEngine or RazorViewEngine). Add an empty constructor. It should looks like this:

    namespace MySite
    {
        public class MySiteViewEngine : RazorViewEngine // <<-- or WebFormViewEngine
        {
             public MySiteViewEngine()
             {
                 // We'll put some code here in a later step
             }
        }
    }
    

    Now, add the following lines to the Application_Start method of Global.asax.cs:

    ViewEngines.Engines.Clear();
    ViewEngines.Engines.Add(new MySiteViewEngine());
    

    At this point, compile and run your application. Everything should be running exactly like it is running now. You’re basically using the same view engine you were using before.

    But now, we want to add a location to search when looking for PartialViews. This is simply done by adding to the PartialViewLocationFormats. So, now in the constructor of your custom view engine, you want to add to the base class’ array like so:

    base.PartialViewLocationFormats = new string[] {
        "~/Views/Templates/{0}.cshtml"
    }.Union(base.PartialViewLocationFormats).ToArray<string>();
    

    A couple of notes about the above:

    • The entry above will make it so that your view engine looks for the String display template at ~/Views/Templates/DisplayTemplates/String.cshtml.
    • The location format in these view engines includes the file extension, so if you’re using Razor/C# use “cshtml”, Razor/VB use “vbhtml”, WebForms add “aspx” and “ascx”.
    • The way I’m doing it above, I’m adding my location format to the top of the list but keeping all the default locations. You might consider removing those.
    • Watch the current formats and you’ll see that you will also get a controller in the {1} position in the format, so if you wanted to have a Templates directory underneath every controller you could.
    • Careful, once you get started moving things around with a view engine, it gets addictive. You might find yourself moving everything around.

    Good luck.

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

Sidebar

Related Questions

I'm going nuts here, trying to get my system configured. I have a laptop
I am going to be using C/C++, and would like to know the best
I am going nuts here. I've looked at the following entries and none of
Our designer is going nuts about this and I just cannot find the right
I am going nuts here trying to resolve a cascading update/delete issue :-) I
I'm using Haml in a Rails 3 app, and its newlines drive me nuts!
C#, using VS2010 and I've got something that makes no sense. At startup my
C#, using VS2010 and I've got something that makes no sense. At startup my
Either i'm going nuts or nobody likes/liked this feature, but a long time ago
I'm going nuts on this. (as most people posting here lol) I have a

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.