net我正在尝试从以前的形式中获取一个值,通常在php中是这样写的。
$name= $_POST ["Username"];
$pass= $_POST ["Password"]; 我如何用asp.net编写这段代码
发布于 2012-06-23 15:30:31
在web表单中
if (Page.IsPostBack)
{
//access posted input as
Request.Form["input1"]
Request.Form["input2"]
Request.Form["input3"]
}在mvc中
[HttpPost]
public ActionResult myaction(strig input1,strig input1,strig input1)
{
//you can access your input here
return View();
}或者如果你有它的视图模型,它能够接受3个输入作为
public class myViewmodleclass()
{
public string input1{get;set;}
public string input2{get;set;}
public string input3{get;set;}
}控制器操作
[HttpPost]
public ActionResult myaction(myViewmodleclass mymodelobject)
{
//you can access your input here
return View();
}发布于 2012-06-23 15:32:53
如果您使用GET
string usrnm = Request.QueryString["username"];
string pass = Request.QueryString["password"];如果您使用POST
string usrnm = Request.Form["username"];
string pass = Request.Form["password"];发布于 2012-06-23 15:37:34
所以你使用mvc,它有一个很好的模型绑定。
所以你使用的是mvc,它有很好的模型绑定。您可以简单地拥有一个适当的模型对象。对于您的示例
public class LoginInfo()
{
public string UserName{get;set;}
public string Password {get;set;}
}在你的控制器中
[HttpPost]
public ActionResult Logon(LoginInfo loginInfo )
{
// Do stuff with loginInfo
}https://stackoverflow.com/questions/11167717
复制相似问题