开发者

Asp.Net MVC3 Razor help, the wrong _ViewStart.cshtml is being called

开发者 https://www.devze.com 2023-02-22 18:46 出处:网络
I 开发者_运维百科have a controller \'QUnitController\', then I have a folder in my Views folder \'QUnit\'. In that folder I have a _ViewStart.cshtml thats coded to use the _Layout file within this fol

I 开发者_运维百科have a controller 'QUnitController', then I have a folder in my Views folder 'QUnit'. In that folder I have a _ViewStart.cshtml thats coded to use the _Layout file within this folder for the Views in the QUnit folder. For some reason the _ViewStart.cshtml in the Views folder is being called and not my _ViewStart.cshtml within the QUnit folder. What am I doing wrong here? I thought having this file in the folder would override the one in the route. I can place break points in the _ViewStart files and I see the one I want is never being hit. Can anyone tell me what I'm doing wrong?

Here is controller code. QUnitController.cs

 public class QUnitController : Controller
{
    public ActionResult LoadView(string viewName)
    {
        return View(viewName);
    }
}

Here is route Views/_ViewStart.cshtml

@{
    Layout = "~/Views/Shared/_Layout.cshtml";

}

Here is qunit Views/QUnit/_ViewStart.cshtml

@{
    Layout = "~/Views/QUnit/_Layout.cshtml";

}

Why am I not calling the correct _ViewStart? Can anyone help me correct the problem? I appreciate any help or tips anyone may have.

Thanks,

~ck in San Diego


All _ViewStart files in every parent folder are executed; the outermost one is executed first.

Your ~/Views/QUnit/_ViewStart.cshtml should be executed last.

Are you sure that your view is coming from the correct folder?


Each area calls its own _ViewStart.cshtml. So in multi-areas context, we need to copy the _ViewStart.cshtml in the ~/View to ~/Areas/YourArea/Views.

0

精彩评论

暂无评论...
验证码 换一张
取 消