title: Passing id in Razor Pages
body: <p>I'm new to Razor Pages and ASP.NET in general.
  So I have a <strong>class</strong> called <strong>UserInfo</strong>. All view models have access to this class.
  On my login page, if login is successful it will pass the <code>UserId</code> and takes me back to the main page. Also updates all information in the <strong>UserInfo</strong>.
  When I try to access that class in view to say hi to the user I can't get any other information than the id that was passed in the url. I cant even run SQL codes to figure it out that way.
  How do I only pass id and find everything else using that id? Is it possible to have that id saved somewhere (in a class or something) so I don't have to pass anything?</p>
  <pre><code>public IActionResult OnPost()
  {
      sqlcon.Open();
      sqlcom = new SqlCommand(&quot;select* from users where userusername='&quot; + Userinfo.Username + &quot;'&quot;, sqlcon);
      SqlDataReader reader = sqlcom.ExecuteReader();
      reader.Read();
      if (reader[2].ToString() == Userpassword)
      {
          Userinfo.UserID = int.Parse(reader[0].ToString());
          Userinfo.Userusername = reader[1].ToString();
          Userinfo.Username = reader[3].ToString();
          return RedirectToPage(&quot;/index&quot;, new { UserId = Userinfo.UserID });
      }
      else
      {               
          return RedirectToPage(&quot;/Login&quot;);
      }
  }
  </code></pre>
  <p>Here is where it says welcome to the user. It only says welcome because somehow <strong>userinfo.username</strong> is still empty even though I assigned a name to it in the login page?! <code>UserId</code> is a variable that i passed to the url that's the only thong that's not empty/null!</p>
  <pre><code>@{
      if (Model.UserId != null)
      {
          &lt;h1 class=&quot;display-4&quot;&gt;Welcome  @Model.UserName&lt;/h1&gt;
      }
      else
      {
          &lt;h1 class=&quot;display-4&quot;&gt;Good to see you!&lt;/h1&gt;
          &lt;label class=&quot;text-secondary&quot;&gt;Please login to access your dashboard&lt;/label&gt;
       }
  }
  </code></pre>