0

我试图从以前的表单中获取一个值,通常是在 php 中,它会这样写

$name= $_POST ["Username"];
$pass= $_POST ["Password"]; 

我怎样才能在asp.net中写这个

4

3 回答 3

1

如果你使用 GET

string usrnm = Request.QueryString["username"];
string pass = Request.QueryString["password"];

如果你使用 POST

 string usrnm = Request.Form["username"];
 string pass = Request.Form["password"];
于 2012-06-23T07:32:53.123 回答
0

在网络表单中

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-23T07:30:31.300 回答
0

所以你使用 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
}
于 2012-06-23T07:37:34.497 回答