了解ASP.NET MVC几种ActionResult的本质:EmptyResult & ContentResult
来源:互联网 发布:淘宝网旺旺在哪里 编辑:程序博客网 时间:2024/04/28 20:12
原文:http://www.cnblogs.com/artech/archive/2012/08/13/action-result-01.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>
0 0
- 了解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的本质:FileResult
- 了解ASP.NET MVC几种ActionResult的本质:FileResult
- 了解ASP.NET MVC几种ActionResult的本质:FileResult
- 了解ASP.NET MVC几种ActionResult的本质:FileResult
- ActionResult的本质一:EmptyResult & ContentResult
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult
- 了解ASP.NET MVC几种ActionResult的本质:HttpStatusCodeResult & RedirectResult/RedirectToRouteResult
- 了解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
- ASP.NET MVC几种ActionResult的本质:FileResult
- ASP.NET MVC的ContentResult
- java.lang.AbstractMethodError: oracle.jdbc.driver.OracleDatabaseMetaData.getJDBCMajorVersion()I异常
- 可变数组无法添加对象的原因
- VS2010下安装boost库
- 344A - Magnets
- Java 序列化的高级认识
- 了解ASP.NET MVC几种ActionResult的本质:EmptyResult & ContentResult
- less学习之编译方法(koala使用说明)
- 大数据技术-HBase:使用CopyTable在线备份HBase表数据
- Redis学习手册(持久化)
- SpringMVC全局文件上传类型限制【终极解决方案】
- Hessian实现Webservice
- Java基础--定时任务Timer
- vs2010:First-chance exception
- 各种杂七咋八的整理