title: ASP.net MVC4: Using a different model in a partial view?
body: <p>I am just learning ASP.net MVC so please bear with me if I am bad at explaining my issue.</p>
  
  <p>Is it possible to use a different model in a partial view than what is being inherited in the view?</p>
  
  <p>My view <code>Index</code> currently inherits <code>LoginModel</code>, which deals with the authorization of users. Once a user is authorized, I want the <code>Index</code> to display the list of <code>todos</code> the user has. <code>todos</code> are retrieved via LINQ.</p>
  
  <p>So my partial view wants to inherit <code>System.Web.Mvc.ViewPage&lt;IEnumerable&lt;todo_moble_oauth.Models.todo&gt;&gt;</code>, but I get an error when I use this: `The model item passed into the dictionary is of type </p>
  
  <pre><code>System.Data.Linq.DataQuery`1[todo_moble_oauth.Models.todo]', but this dictionary requires a model item of type 'todo_moble_oauth.Models.LoginModel'
  </code></pre>
  
  <p>This is my <code>Index</code> view</p>
  
  <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;todo_moble_oauth.Models.LoginModel&gt;" %&gt;
  
  &lt;section id="loginForm"&gt;
      &lt;% if (Request.IsAuthenticated) { %&gt;
  
          &lt;% Html.RenderPartial("_ListTodos"); %&gt;
  
      &lt;% } else { %&gt;
  
          &lt;h1&gt;Todo Mobile&lt;/h1&gt;
  
          &lt;blockquote&gt;Easily store your list of todos using this simple mobile application&lt;/blockquote&gt;
  
          &lt;% using (Html.BeginForm()) { %&gt;
              &lt;%: Html.AntiForgeryToken() %&gt;
              &lt;%: Html.ValidationSummary(true) %&gt;
  
                      &lt;%: Html.LabelFor(m =&gt; m.UserName) %&gt;
                      &lt;p class="validation"&gt;&lt;%: Html.ValidationMessageFor(m =&gt; m.UserName) %&gt;&lt;/p&gt;
                      &lt;%: Html.TextBoxFor(m =&gt; m.UserName) %&gt;
  
                      &lt;%: Html.LabelFor(m =&gt; m.Password) %&gt;
                      &lt;p class="validation"&gt;&lt;%: Html.ValidationMessageFor(m =&gt; m.Password) %&gt;&lt;/p&gt;
                      &lt;%: Html.PasswordFor(m =&gt; m.Password) %&gt;
  
                      &lt;label class="checkbox" for="RememberMe"&gt;
                          &lt;%: Html.CheckBoxFor(m =&gt; m.RememberMe) %&gt;
                          Remember Me?
                      &lt;/label&gt;
  
              &lt;input type="submit" value="Login" /&gt;
          &lt;% } %&gt;
      &lt;% } %&gt;
  &lt;/section&gt;
  </code></pre>
  
  <p>My partial view <code>_ListTodos</code> is as follows:</p>
  
  <pre><code>&lt;%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage&lt;IEnumerable&lt;todo_moble_oauth.Models.todo&gt;&gt;" %&gt;
  
  &lt;% foreach (var item in Model) { %&gt;
        &lt;%: Html.DisplayFor(modelItem =&gt; item.title) %&gt;
        &lt;%: Html.DisplayFor(modelItem =&gt; item.description) %&gt;
  &lt;% } %&gt;
  </code></pre>
  
  <p>My <code>LoginModel</code> has the following:</p>
  
  <pre><code>public class LoginModel
  {
      [Required]
      [Display(Name = "User name")]
      public string UserName { get; set; }
  
      [Required]
      [DataType(DataType.Password)]
      [Display(Name = "Password")]
      public string Password { get; set; }
  
      [Display(Name = "Remember me?")]
      public bool RememberMe { get; set; }
  }
  </code></pre>
  
  <p>The <code>HomeController</code> <code>Index()</code> method:</p>
  
  <pre><code>    [AllowAnonymous]
      public ActionResult Index()
      {
          // if user is logged in, show todo list
          if (Request.IsAuthenticated)
          {
              //var currentUser = Membership.GetUser().ProviderUserKey;
              todosDataContext objLinq = new todosDataContext();
              var todos = objLinq.todos.Select(x =&gt; x);
              return View(todos);
          }
          return View();
      }
  </code></pre>
  
  <p>Any help is greatly appreciated, thanks.</p>