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

Help! I Can't get Ajax Binding to work

3 Answers 98 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.
Mark Rabjohn
Top achievements
Rank 1
Mark Rabjohn asked on 11 May 2010, 01:45 PM
Hi,

I am trying to get Ajax binding to work with my Grid, but it won't work. When I put the callback URL straight into the browser it says that it can't find the view for my callback:

The view 'ViewSite_FillDomainsList' or its master was not found. The following locations were searched:
~/Views/Admin/ViewSite_FillDomainsList.aspx
~/Views/Admin/ViewSite_FillDomainsList.ascx
~/Views/Shared/ViewSite_FillDomainsList.aspx
~/Views/Shared/ViewSite_FillDomainsList.ascx


The code works in my environment using the Q1 Examples project, so I don't know what's wrong.

My Client side code is in C# and looks like this:

            <%= Html.Telerik().Grid<ApexCMS.SiteAddress>() 
                                    .DataBinding(dataBinding => dataBinding.Ajax().Select("ViewSite_FillDomainsList", "Admin", new { guid = Model.Guid.ToString() })) 
                                    .Name("DomainListGrid") 
                                    .Columns(columns => 
                                    { 
                                        columns.Bound(o => o.Scheme); 
                                        columns.Bound(o => o.Domain); 
                                        columns.Bound(o => o.Port); 
                                    }) 
                                    .Sortable() 
            %> 
 

And my server side in VB looks like this:

    <GridAction()> _ 
    Function ViewSite_FillDomainsList(ByVal guid As StringAs ActionResult 
        Dim s As ISession = NHibernateHelper.OpenSession() 
        Dim site As Site = s.CreateCriteria(Of Site).Add(Expression.Eq("Guid"New Guid(guid))).UniqueResult(Of Site)() 
        Dim siteaddresses As IList(Of SiteAddress) = s.CreateCriteria(Of SiteAddress).Add(Expression.Eq("Parent", site)).List(Of SiteAddress)() 
        Dim g As GridModel(Of SiteAddress) = New GridModel(Of SiteAddress)(siteaddresses) 
 
        Return View(g) 
    End Function 
 

The program generates a GridModel in "g" and also get's past the return View(g) line. It also appears to trace right through the GridAction Attribute, but then crashes looking for the View to render.

Surely this can't be a VB vs. C# issue can it? Hopefully it's a common issue and someone will know what I've done.

Best Regards,

Mark








3 Answers, 1 is accepted

Sort by
0
Mark Rabjohn
Top achievements
Rank 1
answered on 11 May 2010, 02:18 PM
It looks as though the error that I'm getting is misleading, because the GridAction doesn't filter the output unless it's an AjaxRequest.

When it's an ajax request, the filterContext.Result is changed to a JsonResult object, but it comes through the filter a second time. I can't see the error, so I'm not sure what's going on.

How can I get a look at the root exception?

Mark
0
Atanas Korchev
Telerik team
answered on 11 May 2010, 02:19 PM
Hi Mark Rabjohn,

Have you tried running with the debugger? Add a break point in the action method which is responsible for delivering the ajax data.

All the best,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mark Rabjohn
Top achievements
Rank 1
answered on 11 May 2010, 02:46 PM
Hi Atanas,

The break occurs outside of anywhere that I have open source code for - maybe if I had MVC source open, but I don't.

In anycase, I found that the problem was that my data struct had a circular reference condition (discovered using Fiddler as suggested in another thread).

I used that solution, i.e. write a read-only view class and use LINQ to add wrappers to my list objects. This is a bit of a pain though.

New Server side code:

 
 
    <GridAction()> _ 
    Function ViewSite_FillDomainsList(ByVal guid As StringAs ActionResult 
        Dim s As ISession = NHibernateHelper.OpenSession() 
        Dim site As Site = s.CreateCriteria(Of Site).Add(Expression.Eq("Guid"New Guid(guid))).UniqueResult(Of Site)() 
        Dim siteaddresses As IEnumerable(Of SiteAddressView) = From sa In (s.CreateCriteria(Of SiteAddress).Add(Expression.Eq("Parent", site)).List(Of SiteAddress)()) Select New SiteAddressView(sa) 
 
        Return View(New GridModel(Of SiteAddressView)(siteaddresses)) 
    End Function 
 
Public Class SiteAddressView 
    Private _obj As SiteAddress 
 
    Public Sub New(ByVal obj As SiteAddress) 
        _obj = obj 
    End Sub 
 
    Public ReadOnly Property Guid() As Guid 
        Get 
            Return _obj.Guid 
        End Get 
    End Property 
 
    Public ReadOnly Property Scheme() As String 
        Get 
            Return _obj.Scheme 
        End Get 
    End Property 
 
    Public ReadOnly Property Domain() As String 
        Get 
            Return _obj.Domain 
        End Get 
    End Property 
 
    Public ReadOnly Property Port() As String 
        Get 
            Return _obj.Port 
        End Get 
    End Property 
End Class 
 


In a perfect world, I guess we'd be able to have attributes to mark properties that can cause circular references, and a JSON encoder that can skip them!

I just need to find the forum postings on getting the Ajax binding to run when the Grid is loaded via Ajax initially - something about including some specific script files I understand.

Best Regards,

Mark
Tags
Grid
Asked by
Mark Rabjohn
Top achievements
Rank 1
Answers by
Mark Rabjohn
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or