title: ASP.NET MVC Nullreferenceexception: System.Web.Mvc.WebViewPage<TModel>.Model.get.<Field at offset 0x00000004> was null
body: <p>I'm working on a project (ASP.NET MVC) for school but today I ran into this error. I'm already trying to fix this for a few hours but nothing works.
  In this application you log in and your profile will load. This works, but as soon as I change the profile data (in a form), post it, and return the view with a refreshed viewmodel (this still works perfectly fine), I get this nullreferenceexception. I've been looking through this exception details but can't figure out whats null, and what's causing this exception.</p>
  
  <p>This is my view:</p>
  
  <pre><code>@model SailyWebApp.Viewmodels.HomeUserViewmodel
  @{
      ViewBag.Title = "Index";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  &lt;body&gt;
      @if(Session["User"] != null &amp;&amp; !string.IsNullOrEmpty(Convert.ToString(Session["User"])))
       {
      &lt;h2&gt;Profile of @Session["User"].ToString()&lt;/h2&gt;
      &lt;form runat="server" method="post" id="userdata"&gt;
          Name:&lt;br&gt;
          &lt;input type="text" name="Name" value="@Model.user.UserName" required /&gt;&lt;br&gt;
          Adress:&lt;br&gt;
          &lt;input type="text" name="Address" value="@Model.user.Adress" required /&gt;&lt;br&gt;
          City:&lt;br&gt;
          &lt;input type="text" name="City" value="@Model.user.City" required /&gt;&lt;br&gt;
          E-mail:&lt;br&gt;
          &lt;input type="text" name="Mail" value="@Model.user.MailAdress" required /&gt;&lt;br&gt;
          Phone number:&lt;br&gt;
          &lt;input type="text" name="Phonenumber" value="@Model.user.PhoneNumber" required /&gt;&lt;br&gt;
          Profile description:&lt;br&gt;
          &lt;input type="text" name="Description" value="@Model.user.Description" required /&gt;&lt;br&gt;
          &lt;input type="submit" name="Save" value="Save" /&gt;
      &lt;/form&gt;
      }
      else{
      &lt;p&gt;Please log in&lt;/p&gt;
      }
  &lt;/body&gt;
  </code></pre>
  
  <p>My HomeController looks like this:</p>
  
  <pre><code>public ActionResult Index()
      {
          if (Session["User"] != null)
          {
              User currentUser = (User)Session["User"];
              HomeUserViewmodel viewmodel = new HomeUserViewmodel();
              viewmodel.user = currentUser;
              return View(viewmodel);
          }
  
          return View();
      }
      [HttpPost]
      public ActionResult Index(HomeUserViewmodel viewmodel)
      {
          User currentUser = (User)Session["User"];
          if (Logic.UserLogic.EditProfile(viewmodel.Address, viewmodel.City, viewmodel.Mail, viewmodel.Phonenumber, viewmodel.Description, currentUser.UserId))
          {
              currentUser = Logic.UserLogic.LoadUser(currentUser.UserId);
              HomeUserViewmodel newviewmodel = new HomeUserViewmodel();
              viewmodel.user = currentUser;
              Session.Clear();
              Session["User"] = currentUser;
              return View(newviewmodel);
          }
          else
          {
              return View();
          }
      } 
  </code></pre>
  
  <p>My HomeUserViewmodel</p>
  
  <pre><code>public class HomeUserViewmodel
  {
      public User user;
  
      private string name;
      private string address;
      private string city;
      private string mail;
      private string phonenumber;
      private string description;
  
      public string Name
      {
          get { return name; }
          set { name = value; }
      }
      public string Address
      {
          get { return address; }
          set { address = value; }
      }
      public string City
      {
          get { return city; }
          set { city = value; }
      }
      public string Mail
      {
          get { return mail; }
          set { mail = value; }
      }
      public string Phonenumber
      {
          get { return phonenumber; }
          set { phonenumber = value; }
      }
      public string Description
      {
          get { return description; }
          set { description = value; }
      }
  }
  </code></pre>
  
  <p>Exception details:</p>
  
  <p>System.NullReferenceException: 'object reference not set to an instance of an object'</p>
  
  <p>System.Web.Mvc.WebViewPage.Model.get. was null.</p>
  
  <p>Thanks in advance, I just really don't know where I can find this null value</p>