简体   繁体   English

模型绑定到列表

[英]Model Binding To A List

I have the following code in my App:- 我的应用程序中包含以下代码:-

<tbody>
                    @{ int intCounter = 0; }
                    @foreach (var item in Model.TimeLogs)
                    {
                        intCounter++;
                        <tr>

                            <td>@intCounter</td>
                            <td>@item.EntryTypeInfo.EntryTypeName</td>
                            <td>@Html.Raw(item.TaskId == 0 ? item.Comments : "<a href=\"/Tasks/Profile/" + @item.TaskId.ToString() + "\" target=\"_blank\" title=\"Click for task profile\">" + @item.Comments + "</a>")</td>
                            <td style="text-align: right;">@item.SubTotal.ToString("c")</td>
                            <td style="text-align: center;"><input id="@item.TimeLogId" class="timeLogItem" type="checkbox" data-amount="@item.SubTotal" data-timelogid="@item.TimeLogId" /></td>

                        </tr>
                    }

                    </tbody>

I want all these things to be binded into a list. 我希望将所有这些东西绑定到列表中。 and the checkbox I am using should return all the checked items in a collection. 并且我使用的复选框应返回集合中所有选中的项目。

How can i do this? 我怎样才能做到这一点?

Regards Abhishek 问候阿比舍克

Add a Checked property on your ViewModel then bind it to a checkbox using Html.CheckBoxFor then route the values back to your controller. 在ViewModel上添加一个Checked属性,然后使用Html.CheckBoxFor将其绑定到复选框,然后将值路由回您的控制器。 At the controller, you can now query all checked items using LINQ. 现在,在控制器上,您可以使用LINQ查询所有选中的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM