前台表单(V:视图)
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>
方式一(C:控制器)
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 }
方式二(C:控制器)
1 /// <summary> 2 /// 方式二 3 /// </summary> 4 /// <param name="collection">应用程序的窗体值提供程序</param> 5 /// <returns></returns> 6 public ActionResult ProcessUserRegist(FormCollection collection) 7 { 8 string userId = collection["UserId"]; 9 return Content(userId + "注册成功!"); //相当于 Response.Write("");Response.End(); 10 }
方式三(C:控制器)
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 + "注册成功!"); //相当于 Response.Write("");Response.End(); 10 }
方式四(C:控制器)
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 }