net I am trying to take a value from a previous form typically in php it would be written like this
$name= $_POST ["Username"];
$pass= $_POST ["Password"];
how can I write this in asp.net
net I am trying to take a value from a previous form typically in php it would be written like this
$name= $_POST ["Username"];
$pass= $_POST ["Password"];
how can I write this in asp.net
if you use GET
string usrnm = Request.QueryString["username"];
string pass = Request.QueryString["password"];
if you use POST
string usrnm = Request.Form["username"];
string pass = Request.Form["password"];
in web forms
if (Page.IsPostBack)
{
//access posted input as
Request.Form["input1"]
Request.Form["input2"]
Request.Form["input3"]
}
in mvc
[HttpPost]
public ActionResult myaction(strig input1,strig input1,strig input1)
{
//you can access your input here
return View();
}
or if you have view model for it, which is capable to take 3 inputs as
public class myViewmodleclass()
{
public string input1{get;set;}
public string input2{get;set;}
public string input3{get;set;}
}
controller action
[HttpPost]
public ActionResult myaction(myViewmodleclass mymodelobject)
{
//you can access your input here
return View();
}
so you using mvc, which has a nice model binding.
So you are using mvc which has nice model binding. You can simply have a proper model object. For your example
public class LoginInfo()
{
public string UserName{get;set;}
public string Password {get;set;}
}
in your controller
[HttpPost]
public ActionResult Logon(LoginInfo loginInfo )
{
// Do stuff with loginInfo
}