0

我有一个表单,在页面顶部有一个输入部分,在下半部分它显示了已添加对象的列表。我需要能够编辑和删除这些对象,但我不确定从哪里开始或如何做。

此代码显示对象列表。

                @if (Model.ListOfRecipients != null)
            {
                for (int i = 0; i < Model.ListOfRecipients.Count; i++)
                {

                <div class='recipient-wrapper'>
                    <div class='decision_block'>
                        <table class='recipient'>
                            <tr>
                                <td class='recipient-title'>
@Html.HiddenFor(model=>model.ListOfRecipients[i].RecipientId)
                                    <h3>
                                        @Html.DisplayTextFor(model => model.ListOfRecipients[i].RecipientName)
                                        @Html.HiddenFor(model => model.ListOfRecipients[i].RecipientName)
                                    </h3>

                                    <div class='delivery-type'>
                                        Delivery Type: @Html.DisplayTextFor(model => model.ListOfRecipients[i].DeliveryType)
                                                       @Html.HiddenFor(model => model.ListOfRecipients[i].DeliveryType)
                                    </div>
                                </td>
                                <td class='na express'>
                                    @Html.CheckBoxFor(model => model.ListOfRecipients[i].ExpressIndicator)
                                    @Html.HiddenFor(model => model.ListOfRecipients[i].ExpressIndicator)
                                </td>
                                <td class='quantity'>
                                    <h3>
                                      Qty @Html.DisplayTextFor(model => model.ListOfRecipients[i].Quantity)
                                          @Html.HiddenFor(model => model.ListOfRecipients[i].Quantity)
                                    </h3>
                                </td>
                                <td class='action'>
                                    <input class='button edit_recipient' type='button' value='Edit' />
                                    <input class='button delete_recipient' type='button' value='Delete' />
                                </td>
                            </tr>
                        </table>

                            <input class='button update_recipient' type='button' value='Update' />
                            <a class='cancel_update' href='#'>Cancel</a>
                        </div>
                    </div>
                </div>

                }
            }
4

2 回答 2

0

您可以创建一个删除控制器和一个编辑控制器,在上面的视图中,每个控制器旁边都有一个删除和编辑,它接收对象 id,每个按钮都转到它自己的视图,在那里他们可以编辑或删除

于 2012-09-17T16:10:21.547 回答
0

您需要在控制器中编写 Edit 和 Delete 操作方法,然后设置两个按钮以调用适当的方法。

操作方法的代码将取决于几个因素,这些因素可能会在这里广泛讨论。

使用 Razor 语法 - 抱歉其他人使用了错误的标记:(

<input class='button edit_recipient' type='button' value='Edit' 
       onclick="location.href='@Url.Action("Edit", "Controller", new { id = Model.Id } )'" />
于 2012-09-17T16:13:47.800 回答