Reception form (V: View)
1 @{ 2 Layout = null; 3 } 4 5 <!DOCTYPE html> 6 7 <html> 8 <head> 9 <meta name="viewport" content="width=device-width" /> 10 <title>UserRegist</title> 11 </head> 12 <body> 13 <div> 14 <form action="/UserInfo/ProcessUserRegist" method="post"> 15 <table> 16 <tr> 17 <td>用户名:</td><td><input type="text" name="UserId" /></td> 18 </tr> 19 <tr> 20 <td>密码:</td><td><input type="password" name="pwd" /></td> 21 </tr> 22 <tr> 23 <td colspan="2"> 24 <input type="submit" value="提交"/> 25 <input type="reset" value="重置"/> 26 </td> 27 </tr> 28 </table> 29 </form> 30 </div> 31 </body> 32 </html>
A manner (C: control)
1 /// <summary> 2 /// 方式一 3 /// </summary> 4 /// <returns></returns> 5 public ActionResult ProcessUserRegist() 6 { 7 string userId = Request.QueryString["UserId"] ?? Request.Form["UserId"]; 8 string pwd = Request.QueryString["pwd"] ?? Request.Form["pwd"]; 9 return Content(userId + "注册成功!"); //相当于 Response.Write("");Response.End(); 10 }
Second way (C: control)
. 1 /// < Summary > 2 /// two ways . 3 /// </ Summary > . 4 /// < param name = "Collection" > form values application provider </ param > . 5 /// < Returns > </ Returns > . 6 public ActionResult ProcessUserRegist (the FormCollection Collection) . 7 { . 8 String the userId = Collection [ "the UserId"]; . 9 return Content (userId + "registered successfully!"); // equivalent of Response.Write ( ""); Response.End (); 10 }
Three ways (C: control)
1 /// <summary> 2 /// 方式三 3 /// </summary> 4 /// <param name="UserId"></param> 5 /// <param name="pwd"></param> 6 /// <returns></returns> 7 public ActionResult ProcessUserRegist(string UserId,string pwd) 8 { 9 return Content (UserId + "registered successfully!"); // equivalent of Response.Write ( ""); Response.End (); 10 }
Four ways (C: control)
1 /// <summary> 2 /// 方式四 3 /// </summary> 4 /// <param name="result"></param> 5 /// <returns></returns> 6 public ActionResult ProcessUserRegist(Result result) 7 { 8 return Content(result.UserId + "注册成功!"); //相当于 Response.Write("");Response.End(); 9 } 10 public class Result 11 { 12 public string UserId { get; set; } 13 public string pwd { get; set; } 14 }