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?
-
What code do you have in your viewstart file? – Ashok Padmanabhan Dec 11 '11 at 03:55
-
possible duplicate of [How do I use a common _ViewStart in areas?](http://stackoverflow.com/questions/4109205/how-do-i-use-a-common-viewstart-in-areas) – BenSwayne Aug 07 '12 at 21:44
3 Answers
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.
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.

- 92,674
- 28
- 195
- 291
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.

- 4,189
- 3
- 28
- 36
-
He's referring to sharing a file between Areas, not between views. Areas have their own layout with their own Views folder. – Erik Funkenbusch Dec 11 '11 at 06:00