如何仅从列表

时间:2018-04-13 17:10:32

标签: asp.net-mvc

我有一个对象列表,我希望能够做的是当用户点击与列表中的项目相关联的按钮时,该项目显示在另一个视图中

 @model VitalBits_2._0.Models.VitalBitListModel
<html>
<head>
    <script src="~/Scripts/jquery-3.3.1.min.js"></script>
    <script>
    </script>
</head>
    <body>
    <table>
        <tr>
            <th style="align-content:center">
                Title
            </th>
            <th style="align-content:center">
                Vital Bit Type
            </th>
            <th>
            </th>
        </tr>

        @for (int i = 0; i < Model.VitalBitList.Count; i++)
        {
            using (Html.BeginForm("PopulateEdit_Create", "Configuration", FormMethod.Post))
            {
                <tr>
                    <td style="align-content:center">
                        @Html.HiddenFor(x => Model.VitalBitList[i].ID)
                        @Html.DisplayFor(x => Model.VitalBitList[i].Title)
                        @Html.HiddenFor(x => Model.VitalBitList[i].Title)
                    </td>
                    <td style="align-content:center">
                        @Html.DisplayFor(x => Model.VitalBitList[i].Message)
                        @Html.HiddenFor(x => Model.VitalBitList[i].Message)
                        @Html.HiddenFor(x => Model.VitalBitList[i].IsActive)
                        @Html.HiddenFor(x => Model.VitalBitList[i].IsPriority)
                        @Html.HiddenFor(x => Model.VitalBitList[i].BitType)
                        @Html.HiddenFor(x => Model.VitalBitList[i].Created)
                        @Html.HiddenFor(x => Model.VitalBitList[i].CreatedBy)
                        @Html.HiddenFor(x => Model.VitalBitList[i].LastModified)
                        @Html.HiddenFor(x => Model.VitalBitList[i].LastModifiedBy)
                    </td>
                    <td>
                        <button type="submit">Edit</button>
                    </td>
                </tr>
            }
        }
    </table>

    <div id="CreateEdit"></div>

</body>

这是我的代码目前的情况,但我目前正在获取构造函数值而不是选择的项目

[HttpPost]
    public ActionResult PopulateEdit_Create(VitalBit selectedItem) {
        DataFactory dataFactory = new DataFactory(); 

       //Logic and stuff

        return View("~/Views/Configuration/Create_Edit.cshtml", selectedItem);
    }

换句话说,我一次只能向控制器提交一个项目,还是我必须以不同的方式进行操作?

任何帮助将不胜感激

0 个答案:

没有答案