ネット通常、phpで以前のフォームから値を取得しようとしています。これは次のように記述されます
$name= $_POST ["Username"];
$pass= $_POST ["Password"];
どうすればこれをasp.netに書くことができますか
ネット通常、phpで以前のフォームから値を取得しようとしています。これは次のように記述されます
$name= $_POST ["Username"];
$pass= $_POST ["Password"];
どうすればこれをasp.netに書くことができますか
GET を使用する場合
string usrnm = Request.QueryString["username"];
string pass = Request.QueryString["password"];
POST を使用する場合
string usrnm = Request.Form["username"];
string pass = Request.Form["password"];
そのため、モデルバインディングが優れている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
}
ウェブフォームで
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();
}