2

How to use one unique _viewstart.cshtml to all views and areas/views? I already move my _viewstart to root of the my site, but when I did this happened this error "Unable to cast object of type 'ASP._ViewStart_vbhtml' to type 'System.Web.WebPages.StartPage'.". My .configs are be inside /views folder. What's the problem?

tereško
  • 57,247
  • 24
  • 95
  • 149
Diego Dias
  • 874
  • 3
  • 14
  • 23

3 Answers3

1

How to use one unique _viewstart.cshtml to all views and areas/views?

Not sure if you mean by that 1 file for all or 1 file per area.

If you want to use simply a single _ViewStart file, it must be placed in the Views folder. That is where it is when starting a new MVC3 project.

If you want a file per area please read this post here:

How do I specify different Layouts in the ASP.NET MVC 3 razor ViewStart file?

"Unable to cast object of type 'ASP._ViewStart_vbhtml' to type 'System.Web.WebPages.StartPage'."

This looks like you are mixing Razor with Webforms. If you are using a mixture of view engines, check your Global.asax that both view engines are added.

protected void Application_Start()
{
    ...
    ViewEngines.Engines.Add(new WebFormViewEngine());
    ViewEngines.Engines.Add(new RazorViewEngine());
    ...
}

Try placing your _ViewStart file into the Views folder to start with as that is where it should be.

Community
  • 1
  • 1
Nope
  • 21,907
  • 7
  • 45
  • 72
0

I'm pretty sure you can't put the _ViewStart in the root of your site. The ViewEngine looks for ViewStart in the Views folder. So the only way to share the same ViewStart would be to use a hardlink and make the same file appear in both folders.

Erik Funkenbusch
  • 91,709
  • 28
  • 188
  • 284
0

For a file to be shared it shouldn't be in the root folder of the site. It should be in the Views/Shared folder.

zgirod
  • 4,029
  • 3
  • 25
  • 36