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

[Solved] Grid bind to a ViewModel class?

2 Answers 140 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.
Kenny
Top achievements
Rank 1
Kenny asked on 11 Nov 2009, 11:07 PM
Hello all,
I have my data returned as IQueryable<T>, resides inside a ViewModel class, when I view the page, nothing got displayed inside the GridView, the code outside the GridView displays the same data just fine. Here are my codes:

SongViewModel.cs:
public class SongViewModel 
    public NewestSongsModel NewestSongsModel { getset; } 
    public FeaturedSongsModel FeaturedSongsModel { getset; } 
 
public class NewestSongsModel 
    public IQueryable<Song> NewestSongs { getset; } 
 
public class FeaturedSongsModel 
    public IQueryable<Song> FeaturedSongs { getset; } 

My SongController.cs to populate the model:
var model = new SongViewModel 
    NewestSongsModel = new NewestSongsModel { NewestSongs = sr.RetrieveLatestSongs(5) }, 
    FeaturedSongsModel = new FeaturedSongsModel { FeaturedSongs = sr.RetrieveFeaturedSongs(5) } 
}; 
 
return View(model); 

My View:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NotesnhacWeb.Models.SongViewModel>" %> 
<h2> 
    NEWEST SONGS</h2> 
<% foreach (var song in Model.NewestSongsModel.NewestSongs) 
   {%> 
<li> 
    <%= song.SongTitle%></li
<% } %> 
<h2> 
    FEATURED SONGS</h2> 
<% foreach (var song in Model.FeaturedSongsModel.FeaturedSongs) 
   { %> 
<li> 
    <%= song.SongTitle%></li
<%} %> 
 
 
<%= Html.Telerik().Grid(Model.FeaturedSongsModel.FeaturedSongs) 
       .Name("FeaturedSongs")
       .Render()
       %> 

In my foreach loop, I was able to access the "song" object, and display the SongTitle just fine.

Inside Telerik().Grid(), I've tried to add new column but intellisense won't work, and when I run the code as shown above, nothing got displayed.

Any idea where my problem might be? Thank you very much,
Kenny.

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 12 Nov 2009, 08:35 AM
Hello Kenny,

This is due to a known issue with generic method resolution. Please modify the grid declaration like this:

Html.Telerik().Grid<Song>(Model.FeaturedSongsModel.FeaturedSongs)

Regards,
Atanas Korchev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kenny
Top achievements
Rank 1
answered on 12 Nov 2009, 04:00 PM
Hi Atanas Korchev,
That fixed the problem! Thank you very much.

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