了解ASP.NET MVC几种ActionResult的本质:EmptyResult & ContentResult
2015-05-22 15:18
537 查看
原文:/article/1308161.html
public class HomeController : Controller { //其他成员 public ActionResult Css() { HttpCookie cookie = Request.Cookies["theme"] ?? new HttpCookie("theme", "default"); switch (cookie.Value) { case "Theme1": return Content("body{font-family: SimHei; font-size:1.2em}", "text/css"); case "Theme2": return Content("body{font-family: KaiTi; font-size:1.2em}", "text/css"); default: return Content("body{font-family: SimSong; font-size:1.2em}", "text/css"); } } }
public class HomeController : Controller { //其他成员 public ActionResult Index() { HttpCookie cookie = Request.Cookies["theme"] ?? new HttpCookie("theme", "default"); ViewBag.Theme = cookie.Value; return View(); } [HttpPost] public ActionResult Index(string theme) { HttpCookie cookie = new HttpCookie("theme", theme); cookie.Expires = DateTime.MaxValue; Response.SetCookie(cookie); ViewBag.Theme = theme; return View(); } }
<html> <head> <title>主题设置</title> <link type="text/css" rel="Stylesheet" href="@Url.Action("Css")" /> </head> <body> @using(Html.BeginForm()) { string theme = ViewBag.Theme.ToString(); @Html.RadioButton("theme", "Default", theme == "Default")<span>默认主题(宋体)</span><br/> @Html.RadioButton("theme", "Theme1", theme == "Theme1")<span>主题1(黑体)</span><br/> @Html.RadioButton("theme", "Theme2", theme == "Theme2")<span>主题2(楷体)</span><br /> <input type="submit" value="保存" /> } </body> </html>
相关文章推荐
- 了解ASP.NET MVC几种ActionResult的本质:EmptyResult & ContentResult
- 了解ASP.NET MVC几种ActionResult的本质:EmptyResult & ContentResult
- 了解ASP.NET MVC几种ActionResult的本质:EmptyResult & ContentResult
- 了解ASP.NET MVC几种ActionResult的本质:EmptyResult & ContentResult
- [转]了解ASP.NET MVC几种ActionResult的本质:EmptyResult & ContentResult
- 了解ASP.NET MVC几种ActionResult的本质:EmptyResult & ContentResult
- 了解ASP.NET MVC几种ActionResult的本质:EmptyResult & ContentResult
- 了解ASP.NET MVC几种ActionResult的本质:HttpStatusCodeResult & RedirectResult/RedirectToRouteResult
- 了解ASP.NET MVC几种ActionResult的本质:HttpStatusCodeResult & RedirectResult/RedirectToRouteResult
- 了解ASP.NET MVC几种ActionResult的本质:HttpStatusCodeResult & RedirectResult/RedirectToRouteResult
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult
- 了解ASP.NET MVC几种ActionResult的本质:HttpStatusCodeResult & RedirectResult/RedirectToRouteResult
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult