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

MVC3 Telerik Grid binding Help!

0 Answers 46 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.
Nate
Top achievements
Rank 1
Nate asked on 04 May 2011, 10:20 PM
Ok, this is a really newbie question but I am stumped.
I am trying to use a ViewModel to get my data from an entity object and populate the telerik mvc grid.
At this point I am a bit confused and need your help. 
I understand the error message but I am not sure how I need to fix this since I am really new to MVC.

----ERROR----
Error 1 Cannot implicitly convert type 'System.Linq.IQueryable<MvcMyAPP.T_Project>' to 'System.Linq.IQueryable<mvcMyAPP.ViewModels.ProjectViewModel>'. An explicit conversion exists (are you missing a cast?) ProjectRepository.cs 23 20 MvcMyAPP


I have this viewmodel:

--VIEWMODEL--

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI.WebControls;

namespace mvcMyModel.ViewModels
{
    public class ProjectViewModel
    {
      

        public IQueryable<mvcMyModel.Models.ProjectRepository> ProjectList
        {
            get;
            set;

        }
    }

  
}

--CONTROLLER--

namespace MvcMyAPP.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        ProjectRepository Repository = new ProjectRepository();

        public ActionResult Index()
        {
            ProjectViewModel objProjectViewModel = new ProjectViewModel();
            objProjectViewModel.ProjectList = Repository.GetProjects();
          

            return View(objProjectViewModel);
          
            return View();
        }
       
    }
}

----REPOSITORY (MODEL)-----

namespace mvcMyAPP.Models
{
    public class ProjectRepository
    {

        mvcMyAPP.Models.MYEntities MYDB = new MYEntities();
        //Fetching data from table

        public IQueryable<mvcMyAPP.ViewModels.ProjectViewModel> GetProjects()
        {
            var vProjects = (from tblProjects in MYDB.Projects
                                select tblProjects);

            return vProjects;

        }

       
       
    }
---GRID---

 

 

@{Html.Telerik().Grid(Model.ProjectList)

 

.Name(

 

"Grid")

 

 

.Pageable()

 

.Sortable()

 

.Filterable()

 

.Groupable()

 

.Render();

 

}

Tags
Grid
Asked by
Nate
Top achievements
Rank 1
Share this question
or