Asp.net 对当前操作使用RenderAction()时出现问题

Asp.net 对当前操作使用RenderAction()时出现问题,asp.net,asp.net-mvc-2,components,partial-views,renderaction,Asp.net,Asp.net Mvc 2,Components,Partial Views,Renderaction,我正在用组件架构构建一个ASP.NETMVC2应用程序。有两种不同类型的组件:基本组件(具有渲染局部视图的关联控制器操作)和布局组件(渲染其所有子组件)(基本组件或特定布局中的布局) 下面是我的通用RenderComponent操作方法,它采用组件ID并呈现适当的视图: [ChildActionOnly] public ActionResult RenderComponent(int id) { ComponentRepository repository = new Component

我正在用组件架构构建一个ASP.NETMVC2应用程序。有两种不同类型的组件:基本组件(具有渲染局部视图的关联控制器操作)和布局组件(渲染其所有子组件)(基本组件或特定布局中的布局)

下面是我的通用RenderComponent操作方法,它采用组件ID并呈现适当的视图:

[ChildActionOnly]
public ActionResult RenderComponent(int id)
{
    ComponentRepository repository = new ComponentRepository();
    Component component = repository.GetComponent(id);
    if (component.ControllerName != null && component.ViewName != null)
    {
        // render elementary component
        return PartialView("Elementary", component);
    }
    else 
    {
        // render layout
        return PartialView(component.Layout.ViewName, component);
    }
}
Elementary.ascx呈现基本组件:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyApp.Models.Component>" %>
<% Html.RenderAction(Model.ViewName, Model.ControllerName); %>
目前唯一的现有布局是VerticalLayout.ascx:

问题是:

当我试图呈现一个带有三个关联的基本子组件的示例布局组件时,页面无法呈现。一些调试揭示了以下问题:

RenderComponent5渲染布局视图。 为了呈现布局中的第一个子组件,在视图中调用Html.RenderActionRenderComponent,Core,1。更进一步,我发现实际上调用了RenderComponent5而不是RenderComponent1

这显然会导致布局视图渲染本身的无限循环


为什么会这样?我怎样才能修好它?我的分层组件体系结构是否与ASP.NETMVC不兼容?您将如何在ASP.NETMVC中构建这样一个系统?

好的,我的错。。。当然,它必须在VerticalLayout.ascx中

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyApp.Models.Component>" %>
<% 
    foreach (var child in Model.ChildComponents()) {
%>
    <div class="layout-container">
    <% Html.RenderAction("RenderComponent", "Core", child.ID); %>
    </div>
<%
    }
%>