This is a migrated thread and some comments may be shown as answers.

[Solved] Odd behavior of Ajax.ActionLink in MVC Grid

1 Answer 76 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rick Stone
Top achievements
Rank 1
Rick Stone asked on 17 May 2011, 06:30 AM
A have the following MVC grid:
@(
 Html.Telerik().Grid<QMS.Models.CustomerTableRow>(Model)
        .Name("CustomerTable")
        .Columns(c =>
        {
            c.Template(
                @<text>
                @Ajax.ActionLink("Delete","Delete", new { key = item.CustomerKey },new AjaxOptions{ Confirm="Delete this Customer?",UpdateTargetId = "CustomerTable", HttpMethod = "Delete"})
                </text>
                );
            c.Bound(col => col.FirstName);
            c.Bound(col => col.LastName);
            c.Bound(col => col.Email);
            c.Bound(col => col.HomePhone);
        })
        .Pageable()
        .Sortable()
        .Resizable(res => res.Columns(true))
        .Scrollable()
        )

//Action Method in view
 //[HttpDelete]  <-- can't have this or else a "Resource not found" error occurs
        public ActionResult Delete(String key)
        {
                repo.DeleteCustomer(key);
                return PartialView("CustomerTable", repo.GetCustomerTable());
        }

Some odd things happen when I click on the "Delete" link that I create in the template column.  First, the confirmation message does not appear but the delete action is still called.  Second, even though I have HttpMethod="Delete", If I decorate the action method with [HttpDelete] I get a "resource not found" error.  Finally, this grid is in a partial view and the action method returns the partialview after the delete however all formatting is lost,  it's as if the CSS file is no longer there.  None of this happens if the link is rendered outside of the grid.  I am using version 2011.1.315
 

1 Answer, 1 is accepted

Sort by
0
Rick Stone
Top achievements
Rank 1
answered on 18 May 2011, 05:18 AM
This project was recently converted from MVC2 to MVC3 and I forgot to add jquery.unobtrusive.js.  Including that made all the difference.
Tags
General Discussions
Asked by
Rick Stone
Top achievements
Rank 1
Answers by
Rick Stone
Top achievements
Rank 1
Share this question
or