标签:style blog http color io 使用 java ar strong
在mvc中所有的controller类都必须使用"Controller"后缀来命名并且对Action也有一定的要求:
public ActionResult About() { return View(); // 参数可以返回model对象 }
public ActionResult UserControl() { ViewBag.Message = "部分视图"; return PartialView("ViewUserControl"); }
public ActionResult Content() { return Content("Test Content", "text/html"); // 可以指定文本类型 }
public ActionResult Json() { Dictionary<string, object> dic = new Dictionary<string, object>(); dic.Add("id", 100); dic.Add("name", "hello"); return Json(dic, JsonRequestBehavior.AllowGet); }
public ActionResult JavaScript() { string str = string.Format("alter(‘{0}‘);", "弹出窗口"); return JavaScript(str); }
public ActionResult File() { string fileName = "~/Content/test.zip"; // 文件名 string downFileName = "文件显示名称.zip"; // 要在下载框显示的文件名 return File(fileName, "application/octet-stream", downFileName); }
public ActionResult Empty() { return null; }
public ActionResult Redirect() { // 直接返回指定的url地址 return Redirect("http://www.baidu.com"); }
public ActionResult RedirectResult() { return RedirectToAction("Index", "Home", new { id = "100", name = "liu" }); }
public ActionResult RedirectRouteResult() { return RedirectToRoute("Default", new { controller = "Home", action = "Index"}); }
Controller返回值类型ActionResult
原文地址:http://www.cnblogs.com/tianmahygj/p/3956440.html