title: How do you pass post form variables in ASP.NET C#/Razor?
body: <p>I'm new to C#/Razor and don't know how to pass form data using the post method. Here's what I've tried:</p>
  
  <p>In login.cshtml: </p>
  
  <pre><code>string username = Request.Form["username"];
  string password = Request.Form["password"];
  </code></pre>
  
  <p>And</p>
  
  <pre><code>string username = Request.Form.Get("username");
  string password = Request.Form.Get("password");
  </code></pre>
  
  <p>In _AppStart.cshtml, I tried:</p>
  
  <pre><code>AppState["username"] = HttpContext.Current.Request.Form["username"];
  AppState["password"] = HttpContext.Current.Request.Form["password"];
  </code></pre>
  
  <p>All return nothing.</p>
  
  <p>Here's the form elements in login.cshtml:</p>
  
  <pre><code>&lt;form action="index.cshtml" method="post" data-ajax="false"&gt;
      &lt;input type="text" name="username" placeholder="Username"&gt;
      &lt;input type="password" name="password" placeholder="Password"&gt;
      &lt;button type="submit"&gt;Login&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>