Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在 MVC 3 中创建一个新的局部视图,因为我的应用程序需要此功能。是否可以为我的局部视图设置一个单独的控制器
是的你可以。创建控制器(如果您只需要将控制器用于局部视图,请考虑禁用非子操作调用):
public class FooController : Controller { [ChildActionOnly] public PartialViewResult Bar() { var model = new BarModel(); return PartialView("_Bar", model); } }
并使用它
@Html.RenderAction("Bar", "Foo")