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

[Solved] Telerik MVC 3 GridView Ajax binding

6 Answers 159 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.
Michael
Top achievements
Rank 1
Michael asked on 02 Mar 2012, 09:21 AM
Hello, I have a little problem. It seems that the grid does not call the ajax binding when trying to sort / page / filter. It never gets called.
I'm using the Entity Framework Code first model.
Here is the code :

public ActionResult Index()
{
    ICollection<Group> groups = prismaManager.GroupManager.Select();
    return View(groups);
}
 
[Telerik.Web.Mvc.GridAction]
public ActionResult _Index()
{
    ICollection<Group> groups = prismaManager.GroupManager.Select();
    return View(new Telerik.Web.Mvc.GridModel
    {
        Data = groups
    });
}


Here is the view that is called when accessing for the first time the Index page :

@model ICollection<Prisma.BO.Group>
@{
    ViewBag.Title = "Groups";
}
<fieldset>
    <legend class="noExpand">Groups</legend>
        @{Html.RenderPartial("_Index", Model);}
</fieldset>

and the partial view that should render the grid :

@model ICollection<Prisma.BO.Group>
@{Html.Telerik()
.Grid<Prisma.BO.Group>()
.BindTo(Model)
.Name("Groups")
.Columns(columns =>
    {
        columns.Bound(g => g).Filterable(true).Groupable(true).Sortable(true);
        columns.Bound(g => g.ShortName).Filterable(true).Groupable(true).Sortable(true);
        columns.Bound(g => g.Number).Filterable(true).Groupable(true).Sortable(true);
    })
    .DataBinding(dataBinding =>
        {
            dataBinding.Server().Select("Index", "Group");
            dataBinding.Ajax().Select("_Index", "Group");
        })
        .Sortable()
        .Pageable()
        .Filterable()
        .Groupable()
        .Footer(true)
        .Render();
}


The layout file ( ~master page) :

<head>
@Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.min.css").Combined(true).Compress(true))
</head>
 
<body>
...
@Html.Telerik().ScriptRegistrar().DefaultGroup(group => group.Combined(true).Compress(true)) 
</body>


Unfortunately, I can't get it working.

Is something wrong in any of those file ?

Thanks for you help.

6 Answers, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 02 Mar 2012, 09:56 AM
Hi,

Why do you have 2 select mode?


Try this :
public ActionResult Index()
{
    return View();
}
 
[Telerik.Web.Mvc.GridAction]
public ActionResult _Index()
{
    ICollection<Group> groups = prismaManager.GroupManager.Select();
    return View(new Telerik.Web.Mvc.GridModel
    {
        Data = groups
    });
}


@{
    ViewBag.Title = "Groups";
}
<fieldset>
    <legend class="noExpand">Groups</legend>
        @{Html.RenderPartial("_Index");}
</fieldset>



@{Html.Telerik()
.Grid<Prisma.BO.Group>()
.Name("Groups")
.Columns(columns =>
    {
        columns.Bound(g => g);
        columns.Bound(g => g.ShortName);
        columns.Bound(g => g.Number);
    })
    .DataBinding(dataBinding =>
        {
            dataBinding.Ajax().Select("_Index", "Group");
        })
        .Sortable()
        .Pageable()
        .Filterable()
        .Groupable()
        .Footer(true)
        .Render();
}

Simpler is better :)

Regards,

0
Michael
Top achievements
Rank 1
answered on 02 Mar 2012, 10:16 AM
I've tried what you said :
.DataBinding(dataBinding =>
    {
        //dataBinding.Server().Select("Index", "Group");
        dataBinding.Ajax().Select("_Index", "Group");
    })

but this didn't solve the problem. It is still not using the ajax request. It is like if it was always on server binding.
Am I missing something ?

Thanks
0
Dadv
Top achievements
Rank 1
answered on 02 Mar 2012, 10:29 AM
That's strange because it work for me.

Do you change all the code? (i had change a lot of thing in controller and view)
0
Michael
Top achievements
Rank 1
answered on 02 Mar 2012, 10:56 AM
Yep I changed everything what you changed and it does ... nothing.
On my Index (when arriving on it for the first time -> method Index), my list is empty. It does not get refreshed with the items. And there is no Ajax call processed.
0
Michael
Top achievements
Rank 1
answered on 02 Mar 2012, 11:38 AM
I retried with a clean version of the current project.
It seems that the Ajax call is processed but now I'v ran into an other issue that this a serialization error.

With fiddler I can check the result of the request and this is what is mentioned :

A circular reference was detected while serializing an object of type &#39;System.Data.Entity.DynamicProxies.Group_91F0511435C0FA4494592BA47117B9B70C1A19AAFB464046824DA2E72C426DEE&#39;.

So, does any of you have any idea that could solve this issue ? 
I'm not really familiar with serialization things.

Thanks
0
Dadv
Top achievements
Rank 1
answered on 02 Mar 2012, 12:06 PM
Could you give us a sample project (with the detached database if possible) ?
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Share this question
or