C# @foreach内的渲染块

C# @foreach内的渲染块,c#,asp.net-mvc,C#,Asp.net Mvc,我试图在一个视图中插入不同的模块。 问题是,我试图在foreach循环中渲染一些视图 @model IEnumerable<AZG.Models.Categories> @foreach (var item in Model) { <div role="tabpanel" class="tab-pane active" id="@item.Alias"> <div class="panel-group" id="accordion" rol

我试图在一个视图中插入不同的模块。 问题是,我试图在foreach循环中渲染一些视图

@model IEnumerable<AZG.Models.Categories>

@foreach (var item in Model)
{
    <div role="tabpanel" class="tab-pane active" id="@item.Alias">
        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
            <div class="panel panel-default">
                <div class="panel-heading" role="tab" id="headingThree">
                    <h4 class="panel-title">
                        <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
                            @item.Name
                        </a>
                    </h4>
                </div>
                <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
                    <div class="panel-body">
                        @{Html.RenderAction("PartialSubCategories", "JobReferences", new { id = item.CategoryId });}
                    </div>
                </div>
            </div>
        </div>
    </div>
}
@model IEnumerable
@{Html.RenderAction(“PartialSubCategories”,“JobReferences”,新的{id=item.CategoryId});}
}
对于模型中的每个项目,视图都应该呈现一个动作,该动作应该显示另一个局部视图

问题是,系统意味着,我不必在@foreach中插入“@{”

在这种情况下,是否有任何想法或不打算这样做。

使用

@Html.Action("PartialSubCategories", "JobReferences", new { id = item.CategoryId })

相反。

Html.RenderAction
直接在页面上呈现结果

Html.Action
返回一个字符串作为结果

另外,您不需要在
@foreach
代码块中使用razor代码块
@{…}

试着替换

@{Html.RenderAction("PartialSubCategories", "JobReferences", new { id = item.CategoryId });}


真的吗?我尝试了这么多不同的东西……也许我监督了解决方案。非常感谢=)
@Html.Action("PartialSubCategories", "JobReferences", new { id = item.CategoryId })