title: MVC 4 - Use a different model in partial view
body: <p>Please bear with my <em>noobness</em>, I'm super new to the MVC pattern.</p>
  
  <p><strong>What I'm trying to do</strong></p>
  
  <p>I am building a profile information page for registered users on my site. This page would list data about the user, such as date of birth, telephone number, subscription status, etc.. You get the idea. I would also like to have a form to let users change their password, email address, personal information <strong>on the same page</strong>.</p>
  
  <p><strong>My problem</strong></p>
  
  <p>The user's data comes from my controller via a passed model variable:</p>
  
  <pre><code>public ActionResult Profil()
          {
              var model = db.Users.First(e =&gt; e.UserName == WebSecurity.CurrentUserName);
              return View(model);
          }
  </code></pre>
  
  <p>The output looks like this in my view:</p>
  
  <pre><code>&lt;label&gt;Phone number: &lt;/label&gt;
              @if (Model.PhoneNumber != null)
                      {
                          @Model.PhoneNumber
                      }
                      else
                      {
                          &lt;span class="red"&gt;You haven't set up your phone number yet. &lt;/span&gt;
                      }
  </code></pre>
  
  <p>The form in which the user could change his info would use another model, ProfileModel. So basiccaly I need to use two models in my view, one for outputting information and one for posting data. I thought that using a partial view I can achieve this, but I get this error:</p>
  
  <blockquote>
    <p>The model item passed into the dictionary is of type
    'Applicense.Models.User', but this dictionary requires a model item of
    type 'Applicense.Models.ProfileModel'.</p>
  </blockquote>
  
  <p>Here's what my call to the partial view looks like:</p>
  
  <pre><code> @using (Html.BeginForm())
      {
          @Html.AntiForgeryToken()
          @Html.ValidationSummary()
  
          @Html.Partial("_ModifyProfileInfo")
      }
  </code></pre>
  
  <p>Here's the partial view:</p>
  
  <pre><code>@model Applicense.Models.ProfileModel
  &lt;ul&gt;
      &lt;li&gt;
          @Html.LabelFor(m =&gt; m.Email)
          @Html.EditorFor(m =&gt; m.Email)
      &lt;/li&gt;
      &lt;li&gt;
          @Html.LabelFor(m =&gt; m.ConfirmEmail)
          @Html.EditorFor(m =&gt; m.ConfirmEmail)
      &lt;/li&gt;
      &lt;input type="submit" value="Update e-mail" /&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>And finally here's my ProfileModel:</p>
  
  <pre><code>public class ProfileModel
      {
          [Required]
          [DataType(DataType.EmailAddress)]
          [Display(Name = "New e-mail address")]
          public string Email { get; set; }
  
          [DataType(DataType.EmailAddress)]
          [Display(Name = "Confirm new e-mail address")]
          [Compare("Email", ErrorMessage = "The e-mail and it's confirmation field do not match.")]
          public string ConfirmEmail { get; set; }
      }
  </code></pre>
  
  <p>Am I missing something? What's the proper way to do this?</p>
  
  <p><strong>Edit:</strong>
  I remade my code reflecting Nikola Mitev's answer, but now I have another problem. Here's the error I get:</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object. (@Model.UserObject.LastName)</p>
  </blockquote>
  
  <p>This only occurs when I'm posting the changed e-mail address values. Here's my ViewModel (ProfileModel.cs):</p>
  
  <pre><code>public class ProfileModel
      {
          public User UserObject { get; set; }
  
          [Required]
          [DataType(DataType.EmailAddress)]
          [Display(Name = "Új e-mail cím")]
          public string Email { get; set; }
  
          [DataType(DataType.EmailAddress)]
          [Display(Name = "Új e-mail cím megerősítése")]
          [Compare("Email", ErrorMessage = "A két e-mail cím nem egyezik.")]
          public string ConfirmEmail { get; set; }
  
          [DataType(DataType.EmailAddress)]
          [Display(Name= "E-mail cím")]
          public string ReferEmail { get; set; }
      }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public ActionResult Profil()
          {
              var User = db.Users.First(e =&gt; e.UserName == WebSecurity.CurrentUserName);
  
              var ProfileViewModel = new ProfileModel
              {
                  UserObject = User
              };
  
              return View(ProfileViewModel);
          }
  </code></pre>
  
  <p>And finally here's my <code>user.cs</code> model class:</p>
  
  <pre><code>[Table("UserProfile")]
      public class User
      {
          [Key]
          [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
          public int UserId { get; set; }
          [Column("UserName")]
          public string UserName { get; set; }
          [Column("Email")]
          [Required]
          public string Email { get; set; }
          [Column("FirstName")]
          public string FirstName { get; set; }
          [Column("LastName")]
          public string LastName { get; set; }
          [Column("PhoneNumber")]
          public string PhoneNumber { get; set; }
  ... You get the idea of the rest...
  </code></pre>
  
  <p>I'm thinking it's happening because the model is trying to put data in each <code>required</code> columns into the database.</p>
  
  <p><strong>Edit2:</strong>
  The httppost method of my Profil action:</p>
  
  <pre><code>[HttpPost]
          [Authorize]
          [ValidateAntiForgeryToken]
          public ActionResult Profil(ProfileModel model)
          {
              if (ModelState.IsValid)
              {
  //insert into database
                  return Content("everything's good");
              }
              else
              {
  //outputs form errors
                  return View(model);
              }
          }
  </code></pre>