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

[Solved] Edit link unresponsive in AJAX binding

1 Answer 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Artur
Top achievements
Rank 1
Artur asked on 18 May 2011, 11:48 PM
I've spent the entire day figuring why this doesn't work. Everything is generated properly scripts are loaded, the browser (IE9, Chrome) steps into the tGrid() function when the document loads up, data is retrieved by the Select action, but the AJAX functions are unresponsive (edit, delete, insert, refresh) ie. I click on Edit and the row doesn't change into edit mode. I've skipped some of the code for brevity(namespaces, datacontext, irrelevant actions since the problem is with the Grid not the controller actions)
ASP.NET MVC2 with Telerik Q1 2011
Model:
[KnownType(typeof(ParticipantEditModel))]
public class ParticipantEditModel
{
    [Required]
    public string Name { get; set; }
    [Required]
    public int? Number { get; set; }
    [Required]
    public int Quantity { get; set; }
}
Controller Actions:
[GridAction]
public ActionResult GridIndex(int cusipID)
{
    var cusip = _db.Cusips.SingleOrDefault(c => c.CusipID == cusipID);
    if (cusip == null) throw new NotFoundException();
    return View(new GridModel(cusip.Participants.Select(p=>new ParticipantEditModel(p))));
}
[GridAction]
public ActionResult GridInsert(int cusipID, ParticipantEditModel model)
{
    var cusip = _db.Cusips.SingleOrDefault(c => c.CusipID == cusipID);
    if (cusip == null) throw new NotFoundException();
    var participant = new Participant();
    participant.UpdateWithModel(model);
    cusip.Participants.Add(participant);
    _db.SubmitChanges();
    return View(new GridModel(cusip.Participants.Select(p => new ParticipantEditModel(p))));
}
[GridAction]
public ActionResult GridUpdate(int cusipID, int id, ParticipantEditModel model)
{
    var cusip = _db.Cusips.SingleOrDefault(c => c.CusipID == cusipID);
    if (cusip == null) throw new NotFoundException();
    var participant = cusip.Participants.Single(p => p.Number == id);
    participant.UpdateWithModel(model);
    _db.SubmitChanges();
    return View(new GridModel(cusip.Participants.Select(p => new ParticipantEditModel(p))));
}
[GridAction]
public ActionResult GridDelete(int cusipID, int id, ParticipantEditModel model)
{
    var cusip = _db.Cusips.SingleOrDefault(c => c.CusipID == cusipID);
    if (cusip == null) throw new NotFoundException();
    var participant = cusip.Participants.Single(p => p.Number == id);
    _db.Participants.DeleteOnSubmit(participant);
    _db.SubmitChanges();
    return View(new GridModel(cusip.Participants.Select(p => new ParticipantEditModel(p))));
}

View:


<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<EagleRock.Models.Views.Cusip.EditModel>" %>
<%@ Import Namespace="EagleRock.Models.Views.Cusip" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <div>
        <% Html.Telerik().Grid<ParticipantEditModel>()
            .Name("Grid")
            .DataKeys(dk => dk.Add(c => c.Number))
            .DataBinding(db => db.Ajax()
                .Select("GridIndex", "Cusip")
                .Insert("GridInsert", "Cusip")
                .Update("GridUpdate", "Cusip")
                .Delete("GridDelete", "Cusip")
            )
            .Columns(c => { c.AutoGenerate(true); c.Command(b => { b.Edit(); b.Delete(); }); })
            .Editable(e => e.Mode(GridEditMode.InLine))
            .Render();
        %>
    </div>
    <% Html.Telerik().ScriptRegistrar()
           .Render();
    %>
</body>
</html>



1 Answer, 1 is accepted

Sort by
0
Artur
Top achievements
Rank 1
answered on 19 May 2011, 01:19 AM
Nevermind... I've solved it. My problem laid in the jquery.validate.js file that is included in a ASP.NET MVC 2 project which is version 1.6 and the grid control requires version 1.7+. Even though I've copied every script file from the Scripts folder, the ScriptRegistrar loaded the old jquery.validate.js file instead of jquery.validate.min.js file provided with MVC Extensions.
Tags
Grid
Asked by
Artur
Top achievements
Rank 1
Answers by
Artur
Top achievements
Rank 1
Share this question
or