删除mvc中的多行不起作用

时间:2015-08-31 16:07:36

标签: model-view-controller selected

我有课程连接

public partial class Connections
{
    public System.Guid IdConnection { get; set; }
    [Required(ErrorMessage = "Requienter code hereenter code here`red")]

    public string Sign { get; set; }
    [DataType(DataType.Date)]
    [Required(ErrorMessage = "Required")]
    public System.DateTime Date { get; set; }
    [DataType(DataType.Time)]
    [Required(ErrorMessage = "Required")]
    public System.DateTime Time { get; set; }
    [Required(ErrorMessage = "Required")]
    public double Band { get; set; }
    [Required(ErrorMessage = "Required")]
    public string Modulation { get; set; }
    [Required(ErrorMessage = "Required")]
    public int RST { get; set; }
    public string Comment { get; set; }
   [Required(ErrorMessage = "Required")]
    public string QLS { get; set; }



}

控制器中的方法:

[HttpPost]
    public ActionResult DeleteMultiple(System.Guid[] deleteInputs)

     {
           var db= new MainDbContext();
       var connections = db.Connections.ToList();
       if (deleteInputs == null)
        {

        }

       foreach (var item in deleteInputs)
    {
        Connections con = db.Connections.Find(item);
        db.Connections.Remove(con);
    }
    db.SaveChanges();
    return RedirectToAction("EditDelete", "Connection");

    }

和查看:

@model IEnumerable<RadioSite.Connections>





          @{
    ViewBag.Title = "My connections";
       }






            <table class="table">
                <tr>
                    <th>
                        Select
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Sign)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Date)



                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Time)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Band)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Modulation)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.RST)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Comment)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.QLS)
                    </th>
                    <th colspan="2">
                        Actions                          
                    </th>

                </tr>

                @foreach (var item in Model)
                {
                    <tr>
                        <td>
                            <input type="checkbox" name="deleteInputs" id="deleteInputs" value="@item.IdConnection" />

                        </td>


                        <td>
                            @Html.DisplayFor(modelItem => item.Sign)
                        </td>
                        <td>
                            @Html.ValueFor(modelItem => item.Date, "{0:dd/MM/yyyy}")

                        </td>
                        <td>
                            @Html.ValueFor(modelItem => item.Time, "{0:HH:MM}")
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Band)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Modulation)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.RST)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Comment)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.QLS)
                        </td>

                        <td>
                            @using (Html.BeginForm("Edit", "Connection", FormMethod.Get))
                            {
                                <input type="submit" value="Edit" formaction="/Connection/Edit/@item.IdConnection" />

                            }
                            </td>

                        <td>
                            @using (Html.BeginForm("DeleteItem", "Connection", FormMethod.Post))
                            {
                                <input type="submit" value="Delete" formaction="/Connection/DeleteItem/@item.IdConnection" />



                            }



                        </td>


                    </tr>
                }


            </table>


@using (Html.BeginForm("DeleteMultiple", "Connection", FormMethod.Post))
{
    <input type="submit" value="Delete Selected"/>
}

我选择了网格中的项目(选中复选框),方法:public ActionResult DeleteMultiple(System.Guid[] deleteInputs)数组deleteInputs中的项目始终为空。

1 个答案:

答案 0 :(得分:0)

你的html.beginform指向&#34; DeleteMultiple&#34;没有任何东西传递给它!您需要重新构建视图以在表单中包含输入,或者由于这是一个删除功能,因此对控制器操作进行ajax调用并发送所选复选框的值。