Grid inside BeginForm posts to the wrong action when deleting a row

3 posts, 1 answers
  1. Uwe
    Uwe avatar
    10 posts
    Member since:
    Mar 2008

    Posted 24 Jul 2013 Link to this post

    Having the following code (stripped down version):
    @using (Html.BeginForm(@"Store", @"Admin", FormMethod.Post))
    {
        @(Html.Kendo().Grid((IEnumerable<MyModel>) ViewBag.MyItems)
             .Name(@"grid")
             .Columns(columns =>
             {
                 columns.Bound(pg => pg.Id).Visible(false);
                 columns.Bound(pg => pg.Name).Template(
                          c => Html.ActionLink(c.Name, @"Details", new {id = c.Id}));
                 columns.Command(
                          commands => commands.Destroy().Text("Delete")).Title("Delete");
             })
             .Pageable()
             .Sortable()
             .DataSource(
                  dataSource => dataSource
                   .Server()
                   .Model(model => model.Id(p => p.Id))
                   .Destroy(d => d.Action(@"Item_Destroy", @"Admin")))
             )
    }
    I do experience the following (wrong) behavior:
    1. User clicks the "Delete" button.
    2. The "Store" action of the "BeginForm" is being called, instead of the "Item_Destroy" action.
    My question:

    What have I done wrong in my view?

  2. Answer
    Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 26 Jul 2013 Link to this post

    Hello,

    When binding the data on the server the Grid uses a form for the delete button and nested forms are not supported by the browsers. You should either use Ajax editing and bind the data entirely with Ajax so that a form is not used or move the Grid out of the form.

    Regards,
    Daniel
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Uwe
    Uwe avatar
    10 posts
    Member since:
    Mar 2008

    Posted 26 Jul 2013 Link to this post

    Somewhat related in my case and just as a references for others, one can have the form's submit button outside the BeginForm area.
Back to Top