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;
}
Use the following
The above code will search for the following views.
or to be more direct
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.