I have a pretty basic question, but I cannot find the answer online without resorting to asking it myself. In an ASP.NET MVC 2 WebSite, if I have a Shared view located in a Shared folder. Let's say the view is called Error, where is the controller for this View? Do I create a SharedController?
1 Answer
You don't create a SharedController. In any controller you want the view available, either create a Method called Error or have a Method return View("Error").
Basically if MVC can't find the View in the Controller Named Directory it looks in the Shared folder for it (which also works for Partial Views and Controls).
2 Comments
Steve Kiss
Hmmm.. What if I want the view to be available in ALL controllers? Can I just create the Method in a base controller and have them all inherit?
Erik Philips
That certainly is one way to go about it. I never had a need for that.