下面介绍几种简单的Action:
1 //默认Action 2 public ActionResult Index() 3 { 4 return View(); 5 } 6 //传递参数Action 7 public ActionResult ShowText(string id) 8 { 9 this.ViewData["Text"] = id; 10 return View(); 11 } 12 //跳转指定页Action 13 public ActionResult Tomicrosoft() 14 { 15 16 return this.Redirect("http://www.microsoft.com"); 17 } 18 //跳转到指定Action的Action 19 public ActionResult ToIndex() 20 { 21 // return this.RedirectToAction("Index"); 22 return this.RedirectToAction("Index","ActionDemo"); 23 } 24 //空的ActionResult 25 public ActionResult empty() 26 { 27 return new EmptyResult(); 28 } 29 protected override void HandleUnknownAction(string actionName) 30 { 31 this.Response.Redirect("~/ActionDemo/Index"); 32 }
第一个默认的Action,就不多说了,剩下的都有注释,注意下HandleUnknownAction是UrlRoute未找到对应的Action后就会执行此Action。
|
请发表评论