title: Model Item type ambiguity when using PagedList
body: <p>I am developing a web survey application in ASP.Net Mvc3. I use PagedList in my application to paginate the questions page alone. </p>
  
  <p>I get the following error:</p>
  
  <pre><code>The model item passed into the dictionary is of type
  'PagedList.PagedList`1[SWSSMVC.Models.ViewModels.QuestionViewModel]', 
  but this dictionary requires a model item of type 
  'PagedList.IPagedList`1[SWSSMVC.Models.ViewModels.QuestionListViewModel]'.
  </code></pre>
  
  <p>There is a <a href="https://stackoverflow.com/questions/6521775/the-model-item-passed-into-the-dictionary-is-of-type-models-app-but-what">question</a> which is of similar nature. The solution says not to specify anonymous type, as far as I understood. Can someone point out where in my code I have anonymous type? I believe I have typed all my variables with appropriate models.</p>
  
  <p>This is the question Controller:</p>
  
  <pre><code>public class QuestionController : SessionController
  {
      DBManager dbmgr = new DBManager();
  
      //
      // GET: /Question/
  
      public ActionResult Index(string currentSection, string currentPage, int? page)
      {
          int j;
  
          SectionSession = currentSection;
          PageSession = currentPage;
  
          var questionList = new QuestionListViewModel();
  
          int questionCount = dbmgr.getQuestionCount(currentPage);
          var question = new QuestionViewModel();
          for(int i=1 ; i&lt;=questionCount; i++)
          {
              int questionid = dbmgr.getQuestionid(currentPage, i);
              string questiontext = dbmgr.getQuestion(questionid);
  
              List&lt;string&gt; oldchoices = dbmgr.getChoicesAns(questionid);
              ChoiceViewModel choice = new ChoiceViewModel();
              question = new QuestionViewModel { QuestionId = questionid, QuestionText = questiontext, Answer = oldchoices.Last()};
  
              for (j = 0; j &lt; oldchoices.Count() - 1; j++)
              {
                  if (oldchoices[j] != null)
                  {
                      question.Choices.Add(new ChoiceViewModel { ChoiceId = j, ChoiceText = oldchoices[j] });
                  }
              }
              questionList.Questions.Add(question);
          }
  
          int pageSize = 3;
          int pageNumber = (page ?? 1);
  
          return View(questionList.Questions.ToPagedList(pageNumber, pageSize));
      }
  </code></pre>
  
  <p>There are two models:</p>
  
  <pre><code>public class QuestionViewModel
  {
      public int QuestionId { get; set; }
      public string QuestionText { get; set; }
      public List&lt;ChoiceViewModel&gt; Choices { get; set; }
      public string Answer { get; set; }
      [Required]
      public string SelectedAnswer { get; set; }
      public QuestionViewModel()
      {
          Choices = new List&lt;ChoiceViewModel&gt;();
      }
  }
  
  public class QuestionListViewModel
  {
      public List&lt;QuestionViewModel&gt; Questions { set; get; }
      public QuestionListViewModel()
      {
          Questions = new List&lt;QuestionViewModel&gt;();
      }
  }
  </code></pre>
  
  <p>I am entering my part- Index View code for the above Question Controller</p>
  
  <pre><code>@model PagedList.IPagedList&lt;SWSSMVC.Models.ViewModels.QuestionListViewModel&gt;
  @{
      ViewBag.Title = "Index";
   }
  
   &lt;h2&gt;Questions&lt;/h2&gt;
  
   @using (Html.BeginForm())
   {
      @Html.ValidationSummary(true)
      &lt;fieldset&gt;
         @foreach (var item in Model)
         {
             @Html.EditorFor(x =&gt; item.Questions)
         }
  </code></pre>
  
  <p>I also have a Editor Template like this</p>
  
  <pre><code>@model SWSSMVC.Models.ViewModels.QuestionViewModel
  &lt;div&gt;
  @Html.HiddenFor(x =&gt; x.QuestionId)
  &lt;h3&gt; @Model.QuestionText &lt;/h3&gt;
  @foreach (var a in Model.Choices)
  {
     &lt;p&gt;
        @Html.RadioButtonFor(b =&gt; b.SelectedAnswer, a.ChoiceText)  @a.ChoiceText 
     &lt;/p&gt;
  }
  &lt;/div&gt;
  </code></pre>
  
  <p>I tried to run through the code a couple of times and having hard time figuring it out. I also do not know how I could have made the questionList as a LINQ variable, given that, my questionList is inturn constructed with questions and choices from a separate model.</p>