MVC Razor绑定到列表中的列表

时间:2015-03-16 10:43:47

标签: c# asp.net-mvc asp.net-mvc-4 razor

我有一个对象列表,里面有一个对象列表,我正在尝试以一种形式绑定到它们,但是当我提交时,子列表将返回null。我希望有人能够找到我出错的地方/或者甚至是可能的。

我的代码如下所示:

@for (var i = 0; i < Model.AlgorithmOutput.Activities.Count; i++)
{
<div id="@("panel" + i)" class="panel panel-danger">
    <div class="panel-heading" role="tab" id="headingOne">
        <h4 class="panel-title">
            <a data-toggle="collapse" data-parent="#accordion" href="#@i" aria-expanded="true" aria-controls="collapseOne">
                @Html.EditorFor(model => model.AlgorithmOutput.Activities[i].ActNo)
                @Html.EditorFor(model => model.AlgorithmOutput.Activities[i].Method)
                @Html.EditorFor(model => model.AlgorithmOutput.Activities[i].Area)
                @Html.EditorFor(model => model.AlgorithmOutput.Activities[i].Exposure)
            </a>
        </h4>
    </div>
    <div id="@i" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
        <div class="panel-body">
            <ul id="@("actSyms" + i)" class="Symbols">
                @for (var x = 0; x < Model.AlgorithmOutput.Activities[i].ActSyms.Count; x++)
                {
                    <li class="actSymItem">
                        <a onclick=" DeleteActSym(this); return false; " href="#"><span class="glyphicon glyphicon-trash"></span></a>
                        @Html.HiddenFor(model => model.AlgorithmOutput.Activities[i].ActSyms[x].CommCode)
                        @Html.Image("../Content/Images/Symbols/" + Model.AlgorithmOutput.Activities[i].ActSyms[x].SymbCode + ".jpg", Model.AlgorithmOutput.Activities[i].ActSyms[x].SymbCode, "dd")
                        @Html.EditorFor(model => model.AlgorithmOutput.Activities[i].ActSyms[x].SymbCode)
                        @Html.EditorFor(model => model.AlgorithmOutput.Activities[i].ActSyms[x].Comment, new { htmlAttributes = new { rows = 3, cols = 12, @class = "form-control" } })
                    </li>
                }
                <a href="#" id="@i" onclick=" NewActSym(this); return false; ">Add</a>
            </ul>

        </div>
    </div>
</div>

}

1 个答案:

答案 0 :(得分:0)

只需要模型中的getter / setter,感谢Stephen Muecke指出