1、Controller中的跳转
(1)直接Redirect后加(Controller/Action):Response.Redirect("/Home/Index");
(2)直接return后加(Controller/Action):return Redirect("/Home/Index");
(3)使用RedirectToAction方法
[1]同一个Controller中,直接跳到一个action:return RedirectToAction("Index");
[2]不在同一Controller中:return RedirectToAction("Index","Home");
2、基类Controller的登录验证
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public class ControllerBase : Controller { /// <summary> /// 重写控制器初始化 /// </summary> protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); if (Session["UserID"] == null) { //验证是否登陆后跳转 Response.Redirect("~/Home/Login"); } } /// <summary> /// 使用FilterAction,重写其 /// </summary> protected override void OnActionExecuting(ActionExecutingContext filterContext) { //加载已登录用户对象和Style数据, 由子类实现 if (Session["UserID"] == null) { filterContext.Result = RedirectToRoute("Default", new { Controller = "Home", Action = "Login" }); return; } } }
3、MVC4.0实现Response.Write()等同效果:
[1]方法一: @{Output.Write("aaaa");}
[2]方式二:public ActionResult myAction() { Return Content("Hello World!"); }
4、显示富文本编辑器编辑过的带格式文本
[1]直接显示:<%: ViewData.Eval("zzModel.D_Content") %>
显示结果:<p>合格 深文巧诋</p>
[2]带格式显示:<%= Server.HtmlDecode(ViewData.Eval("zzModel.D_Content").ToString()) %>
或 <%= HttpUtility.HtmlDecode(ViewData.Eval("zzModel.D_Content").ToString()) %>
显示结果:合格 深文巧诋
[3]Razor 语法下带格式显示:@Html.Raw(Server.HtmlDecode("zzModel.D_Content"))
或 @Html.Raw(HttpUtility.HtmlDecode("zzModel.D_Content"))