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

[Solved] Binding Grid Error

1 Answer 234 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.
regis
Top achievements
Rank 1
regis asked on 05 Apr 2010, 05:14 PM
Good morning everyone,

I am experiencing problem with binding the grid. I have to precise this is my first time using MVC framework and telerik MVC controls.
I try two different ways according to server binding instruction but still get some errors

Unless I am wrong my views are strongly typed according the inherits value of the page declaration.

here is my first way

controller:
public ActionResult Index()  
        {  
            CasEntities db = new CasEntities();  
 
 
            return View(db.NUMBERSet.ToList());  
        }  
 

view:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<AdminCAS.Models.NUMBER>" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">  
    Index  
</asp:Content> 
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">  
 
    <h2>List of CAS Number</h2> 
      
    <%= Html.Telerik().Grid(Model)  
        .Name("NumberGrid")  
        .Pageable()  
        .Sortable()%> 
 
</asp:Content> 
 


Doing this I get the followinf error:
Server Error in '/' Application.  
--------------------------------------------------------------------------------  
 
Compilation Error   
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.   
 
Compiler Error Message: CS0411: The type arguments for method 'Telerik.Web.Mvc.UI.ViewComponentFactory.Grid<T>(System.Collections.Generic.IEnumerable<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.  
 
Source Error:  
 
   
 
Line 9:      <h2>List of CAS Number</h2> 
Line 10:       
Line 11:     <%= Html.Telerik().Grid(Model)  
Line 12:         .Name("NumberGrid")  
Line 13:         .Pageable()  
   
 


So I modify my view specifying the model type into grid declaration:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<AdminCAS.Models.NUMBER>" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">  
    Index  
</asp:Content> 
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">  
 
    <h2>List of CAS Number</h2> 
      
    <%= Html.Telerik().Grid<AdminCAS.Models.NUMBER>(Model)  
        .Name("NumberGrid")  
        .Pageable()  
        .Sortable()%> 
 
</asp:Content> 
 


and get the following error:
Server Error in '/' Application.  
--------------------------------------------------------------------------------  
 
Compilation Error   
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.   
 
Compiler Error Message: CS1502: The best overloaded method match for 'Telerik.Web.Mvc.UI.ViewComponentFactory.Grid<AdminCAS.Models.NUMBER>(System.Collections.Generic.IEnumerable<AdminCAS.Models.NUMBER>)' has some invalid arguments  
 
Source Error:  
 
   
 
Line 9:      <h2>List of CAS Number</h2> 
Line 10:       
Line 11:     <%= Html.Telerik().Grid<AdminCAS.Models.NUMBER>(Model)  
Line 12:         .Name("NumberGrid")  
Line 13:         .Pageable()  
   
 

If someone can point me what I may doing wrong, would be great. Thank you!

1 Answer, 1 is accepted

Sort by
0
regis
Top achievements
Rank 1
answered on 05 Apr 2010, 05:28 PM

Hi,
I manage to get it work by modifying my page declaration to :

 

<%

@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<AdminCAS.Models.NUMBER>>" %>

 


I am just surprised (even if it mention into the introduction of the grid webpage) that my model would be a type IEnumerable as my true model is not a list (Not sure how clear is the last sentence).

But the important is that it's working.
Tags
Grid
Asked by
regis
Top achievements
Rank 1
Answers by
regis
Top achievements
Rank 1
Share this question
or