title: Passing model data to view in MVC 5
body: <p>I am darned new to the world of MVC 5 .NET... I am trying to get my head around the Tree Control from Ignite UI.</p>
  
  <p>I need to retrieve my data from my model and pass it to my view... However, I keep getting the following error:</p>
  
  <blockquote>
    <p>The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery<code>1[System.String]', but this dictionary requires a model item of type 'System.Linq.IQueryable</code>1[DataViewer.Models.Viewer]'.</p>
  </blockquote>
  
  <p>Here is my model:</p>
  
  <pre><code>namespace DataViewer.Models
  {
      [Table("dbo.table")]
      public class Viewer
      {
          [Key, Column(Order=0)] public long id { get; set; }
          public int Revision { get; set; }
          public string GeoPSRType { get; set; }
          public string GeoName { get; set; } 
          public string L2Name { get; set; }  
          public string L3Name { get; set; }
      }
  }
  </code></pre>
  
  <p>etc.</p>
  
  <p>And my Controller:</p>
  
  <pre><code>namespace DataViewer.Controllers
  {
      public class ViewerController : Controller
      {
          private ViewerDBContext db = new ViewerDBContext();
  
          public ActionResult Index()
          {
              var result = db.Items.Select(i =&gt; i.GeoName).Distinct().OrderBy(n =&gt; n);
  
              return View(result);
          }
      }
  }
  </code></pre>
  
  <p>And my view:</p>
  
  <pre><code>@model IQueryable&lt;DataViewer.Models.Viewer&gt;
  
  @using Infragistics.Web.Mvc
  
  @(Html.Infragistics().Tree()
          .DataSource(Model)
          .Bindings(b =&gt;
              b.TextKey("GeoName")
              .PrimaryKey("ID")
              .ValueKey("ID")
              .ChildDataProperty("L2PSRType")
              )
          )
          .DataSource(Model)
          .LoadOnDemand(true)
          .DataSourceUrl(Url.Action("tree-data-on-demand"))
          .DataBind()
          .Render()
  )
  </code></pre>
  
  <p>I figured the issue was that I should be passing a strongly typed  return-type by using </p>
  
  <pre><code>IQueryable&lt;Viewer&gt; result = 
  db.Items.Select(i =&gt; i.GeoName).Distinct().OrderBy(n =&gt; n);
  </code></pre>
  
  <p>but that throws a different error:</p>
  
  <pre><code>InvalidOperationException: The model item passed into the dictionary is of type 
  'System.Data.Entity.Infrastructure.DbQuery`1[System.String]', 
  but this dictionary requires a model item of type 
  'System.Linq.IQueryable&lt;DataViewer.Models.Viewer&gt;.' 
  An explicit conversion exists, are you missing a cast?
  </code></pre>
  
  <p>Is this relating to the fact that I'm pretty rusty on strongly typed syntax, or am I just being a total maroon (or is it a combination)?</p>
  
  <p>P.S. Also, I have no doubt that the Infragistics().Tree() portion of the view is not correct, I am really more concerned about getting my data to my view (at this point). I just wanted to include all code I had...</p>