How do you pass post form variables in ASP.NET C#/Razor?
12:03 27 Oct 2016

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:

In login.cshtml:

string username = Request.Form["username"];
string password = Request.Form["password"];

And

string username = Request.Form.Get("username");
string password = Request.Form.Get("password");

In _AppStart.cshtml, I tried:

AppState["username"] = HttpContext.Current.Request.Form["username"];
AppState["password"] = HttpContext.Current.Request.Form["password"];

All return nothing.

Here's the form elements in login.cshtml:

c# asp.net forms post razor