This project is read-only.

paging with iqueryable not working

Mar 23, 2014 at 1:33 AM
Hi ! I tried to use the grid with iqueryable interface but with no success.

With IEnumerable interface i have no problem. Infact using the following code the grid page correctly. This is the controller:
 public ActionResult Index()
        {
            var userprofiles = db.UserProfiles.Include(u => u.PaymentDetail);
            return View(userprofiles.ToList() );
        }
And the View:
@model IEnumerable<CrowdPublishing.Models.UserProfile>
@using GridMvc.Html

.....

@Html.Grid(Model).AutoGenerateColumns().WithPaging(3)
If instead i try to use IQueryable i got an error in _Grid.cshtml.

In particular
@helper RenderGridBody()
{
    if (!Model.ItemsToDisplay.Any())
    {
Items to display is null.


Controller:
 public ActionResult Index()
        {
            var userprofiles = db.UserProfiles.Include(u => u.PaymentDetail);
            return View(userprofile  );
        }
And the View:
@model IQueryable<CrowdPublishing.Models.UserProfile>
@using GridMvc.Html

.....

@Html.Grid(Model).AutoGenerateColumns().WithPaging(3)
What am I doing wrong?
Mar 24, 2014 at 10:33 AM
UPDATE: i found that this dont work because it seems that the grid doesnt recognize enumerations in the data. Am I right?
Apr 5, 2014 at 8:08 AM
Hi

What you mean about "enumerations in the data."? can you show your model class?
Apr 8, 2014 at 1:19 PM
I mean if the class that i want to use as model contains an Enum the grid throw an exception. Here is my model class:
    public class UserProfile
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int UserId { get; set; }
        public string UserName { get; set; }
       
        public string Name { get; set; }
       
        public string Surname { get; set; }

        string City { get; set; }


        [Required]
        [MaxLength(200)]
        [Index(IsUnique = true)]
        public string Email { get; set; }
 
        public string Signature { get; set; }

        [DataType(DataType.Url)]
        public string GoogleProfile { get; set; }

        public string TwitterId { get; set; }

 
        public string Note { get; set; }

        public UserStatus UserStatus { get; set; }
        public string FormData { get; set; }

        virtual public PaymentDetail PaymentDetail { get; set; }
        virtual public List<Section> UserSections { get; set; }
        virtual public List<Article> Articles { get; set; }
        public UserProfile()
        {
            UserStatus = UserStatus.ToFillForm;

        }
    }

    public enum UserStatus : int
    {
        ToFillForm = 0,
        Pending,
        Approved,
        Refused,
        Suspended
    }


Apr 23, 2014 at 10:40 PM
Incidentally, I am having this exact same issue, except I am not using any enums.
The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NotSupportedException: The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.

Source Error: 


Line 25: @helper RenderGridBody()
Line 26: {
Line 27:     if (!Model.ItemsToDisplay.Any())
Line 28:     {
Line 29:     <tr class="grid-empty-text">

Source File: c:\Dev\MyProject\Views\Shared\_Grid.cshtml    Line: 27 
The View (sanitized a little):
@model IQueryable<Site>
@Html.Grid(Model).Columns(columns =>
        {
            columns.Add(m => m.Name).Sortable(true).Filterable(true);
            columns.Add(m => m.Place).Sortable(true).Filterable(true);
            columns.Add(m => m.Store).Titled("Has Store").Sortable(true).Filterable(true);
            columns.Add(m => m.Cart).Titled("Has Cart").Sortable(true).Filterable(true);
            columns.Add(m => m.Auction).Titled("Has Auction").Sortable(true).Filterable(true);
        }).WithPaging(20)
The Model (also sanitized):
    public class Site
    {
        [Key]
        public int Id { get; set; }
        public string Name { get; set; }
        public string Place { get; set; }
        public bool Store { get; set; }
        public bool Cart { get; set; }
        public bool Auction { get; set; }
    }
Apr 24, 2014 at 12:42 PM
Please use "order By before" assign source.