Q:

RenderAction Block inside @foreach

Im trying to insert diffrent modules into one View.
The problem is, that i try to Render some views inside a foreach Loop.
@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>
}

For every item in the model, the View should render an Action, which should dislpay another Partial View.
The problem is, that the system means, that i don't have to insert "@{" inside a @foreach.
Any ideas or is it not indtended to do that in this case.

A:

Html.RenderAction renders the result directly on the page.
Html.Action returns a string as the result.
Also, you dont need to use the razor code block @{...} inside the @foreach code block.
Try replacing
@{Html.RenderAction("PartialSubCategories", "JobReferences", new { id = item.CategoryId });}

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

