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

[Solved] Ajax binding issues

5 Answers 141 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.
raphael
Top achievements
Rank 1
raphael asked on 10 Oct 2011, 09:39 AM
I cannot understand because when I try to bind via ajax this linq query the grid shows the messase no records to display

@(Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(a => a.Genre.Name).Width(100);
            columns.Bound(a => a.Artist.Name).Width(200);
            columns.Bound(a => a.Title);
            columns.Bound(a => a.Price).Width(120);
        })
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_AjaxBinding", "StoreManager"))
        .Sortable()
        )
controller
public ViewResult Index()
{
    return View();
}
[GridAction]
public ActionResult _AjaxBinding()
{
    var albums = from p in db.Albums
           .Include("Genre")
           .Include("Artist")
           select p;
    return View(new GridModel<Album>
    {
        Data = albums.ToList()
    }
    );
}

Can somebody help me?

Thank you

5 Answers, 1 is accepted

Sort by
0
Jyri
Top achievements
Rank 1
Iron
answered on 11 Oct 2011, 09:06 AM
I am not 100% sure, but might be related to the issues discussed in another thread:

http://www.telerik.com/community/forums/aspnet-mvc/grid/dynamic-object-ajax-binding-issue.aspx#1739384

Brgds,
Jyri
0
raphael
Top achievements
Rank 1
answered on 11 Oct 2011, 11:53 AM
Hi Jyri,

After 2 days trying and trying I found out what the ajax binding didn't like. I'm using a project that comes from microsoft page to see how mvc works
here are 2 simple model for a music store

public class Album
    {
        public int AlbumId { get; set; }
        public string Title { get; set; }
        public decimal Price { get; set; }
        public Genre Genre { get; set; }
        public Artist Artist { get; set; }
        public virtual List<OrderDetail> OrderDetails { get; set; }
    }
  
public class Artist
    {
        public int ArtistId { get; set; }
        public string Name { get; set; }
    }
  
public partial class Genre
        {
            public int GenreId { get; set; }
            public string Name { get; set; }
            public string Description { get; set; }
            //********************************************
            //public List<Album> Albums { get; set;}
            //********************************************
        }

 

I figured out that as soon as I comment the last line in the Genre class the ajax binding begins to work.

 

Now I'm curious to know why that line of code gives me problem when try to do the ajax binding?

 

Raphael

0
Jyri
Top achievements
Rank 1
Iron
answered on 11 Oct 2011, 12:09 PM
Hi Raphael!

Maybe circular reference between your classes?

http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-troubleshooting.html

On that page look the item

Receiving "500 Internal Server Error" during Ajax binding


Brgds,
Jyri
0
raphael
Top achievements
Rank 1
answered on 11 Oct 2011, 01:28 PM
HI Jyri,

That was it. As soon as yu declare the circular reference as internal or private the ajax binding stars to work

Thank you very much

Raphael
0
Jyri
Top achievements
Rank 1
Iron
answered on 11 Oct 2011, 01:38 PM
You're welcome!

Brgds,
Jyri
Tags
Grid
Asked by
raphael
Top achievements
Rank 1
Answers by
Jyri
Top achievements
Rank 1
Iron
raphael
Top achievements
Rank 1
Share this question
or