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 7636767

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:46:05+00:00 2026-05-31T07:46:05+00:00

My knowledge of MVC and Razor is quite basic so I’m hoping its something

  • 0

My knowledge of MVC and Razor is quite basic so I’m hoping its something rather simple. Basically, I have my Controllers as normal but my Views folder has a nested structure. For example, instead of:

Views -> Index.cshtml

It is like

Views -> BrandName -> Index.cshtml

I created a custom helper to work around this, but I’m not sure how it would work with query string urls? As an example here is a controller:

    private DataService ds = new DataService();

    //
    // GET: /Collections/

    public ActionResult Index()
    {
        return View();
    }


    //
    // GET: /Collections/Collection?id=1
    public ActionResult Collection(int id)
    {
        var collectionModel = ds.GetCollection(id);
        return View(collectionModel);
    }

But how do I get ActionResult Collection to look at:

Views -> Brand2 -> Collection.cshtml

Here is the workaround method I was using:

public static string ResolvePath(string pageName)
    {
        string path = String.Empty;
        //AppSetting Key=Brand
        string brand = ConfigurationManager.AppSettings["Brand"];

        if (String.IsNullOrWhiteSpace(brand))
            path = "~/Views/Shared/Error.cshtml"; //Key [Brand] was not specified
        else
            path = String.Format("~/Views/{0}/{1}", brand, pageName);

        return path;
    }
  • 0 0 Answers
  • 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-31T07:46:06+00:00Added an answer on May 31, 2026 at 7:46 am

    Use the following

    public ActionResult Collection(int id)
    {
        var collectionModel = ds.GetCollection(id);
        return View("/Brand2/Collection", collectionModel);
    }
    

    The above code will search for the following views.

    ~/Views/Brand2/Collection.aspx
    ~/Views/Brand2/Collection.ascx
    ~/Views/Shared/Brand2/Collection.aspx
    ~/Views/Shared/Brand2/Collection.ascx
    ~/Views/Brand2/Collection.cshtml
    ~/Views/Brand2/Collection.vbhtml
    ~/Views/Shared/Brand2/Collection.cshtml
    ~/Views/Shared/Brand2/Collection.vbhtml
    

    or to be more direct

    public ActionResult Collection(int id)
        {
            var collectionModel = ds.GetCollection(id);
            return View("~/Brand2/Collection.cshtml", collectionModel);
        }
    

    Now, I want to be the first to warn you that you should never, never, never use this answer. There is a good reason for following the conventions inherent in an MVC application. Placing your files in known locations makes it easier for everyone to understand your application.

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

Sidebar

Related Questions

I'm very new to MVC...I have quite a bit of knowledge with Silver-light and
I have basic knowledge of Java and some experience with MVC pattern. I have
My knowledge of xml and php is somewhat basic but have been able to
So I have a MVC app and in another project I have a normal
I'm learning JSP and have a good working knowledge of PHP and MVC frameworks.
I'm working on my first MVC project. I have very little knowledge on jscript,
I have a need to learn MVC 3 with the Razor view engine and
My knowledge of regex is very weak. So far I have manage to create
Just a knowledge question which I would like to ask: For example, I have
I have an ASP.NET MVC web application running in IIS as a subweb; let's

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.