creating a View within a View
I have a fairly large ASP.NET MVC 2 project that has the Controllers separated into ano开发者_JAVA技巧ther project. I would like to create a View within a parent View.
I have ParentController
and ChildController
, both inheriting from "Controller." I would like to create a folder called "ChildController" within "ParentController" and add Views from there.
Obviously, this throws a "The Resource could not be found" error.
Do I need to edit the controllers? Is this a routing limitation?
(How) can this be achieved?
By default, views checked in the Views/{ControllerPrefix} folder. Then in the Views/Shared folder.
Your folder needs to match the controller's Prefix, ie:
ChildController
will pull views from
/views/child/
You can also directly reference the view based on it's application path from any controller:
~/views/child/subview.ascx
I'm not sure I understand what you're asking, but providing custom view search paths is done by writing a custom ViewEngine
class.
But having multiple controllers (no matter how they're inherited) should always be a folder per controller in the Views
folder.
I guess you're using Html.RenderAction
method. Doesn't really matter. Your View folder structure should still be:
/Views
/Parent
/Index.aspx
/Whatever.aspx
/Child
/SubView.ascx <- this one here is a partial view if you use RenderAction()
精彩评论