爱上MVC3~在控制器或Action上动态设定模板页(Layout)
很多境况下,我们需要设置自己模块的layout,即它的布局页面,在MVC2中叫它模板页面,你可以在return view方法时设置它,当然,这不是一种好方法,因为我不想每个action都去设置一次,因为我们的controller一般指一个模块,而一个模块下的action,它们的layout基本是相同的,所以,有没有一种方法,在controller级别来实现这个呢,呵呵,当然有,那就是attribute特性,我们在MVC环境下,有一个ActionFilterAttribute,这个想毕大家都听说过,它记录了页面在渲染前与渲染后的状态,这个特性(或者叫它过滤器)的代码如下:
// 摘要:
// Represents the base class for filter attributes.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public abstract class ActionFilterAttribute : FilterAttribute, IActionFilter, IResultFilter
{
// 摘要:
// Initializes a new instance of the System.Web.Mvc.ActionFilterAttribute class.
protected ActionFilterAttribute(); // 摘要:
// Called by the ASP.NET MVC framework after the action method executes.
//
// 参数:
// filterContext:
// The filter context.
public virtual void OnActionExecuted(ActionExecutedContext filterContext);
//
// 摘要:
// Called by the ASP.NET MVC framework before the action method executes.
//
// 参数:
// filterContext:
// The filter context.
public virtual void OnActionExecuting(ActionExecutingContext filterContext);
//
// 摘要:
// Called by the ASP.NET MVC framework after the action result executes.
//
// 参数:
// filterContext:
// The filter context.
public virtual void OnResultExecuted(ResultExecutedContext filterContext);
//
// 摘要:
// Called by the ASP.NET MVC framework before the action result executes.
//
// 参数:
// filterContext:
// The filter context.
public virtual void OnResultExecuting(ResultExecutingContext filterContext);
}
OnActionExecuted,OnActionExecuting,OnResultExecuted和OnResultExecuting它们记录一个action从加载到页面最终显示在浏览器上的全过程,这个东西我们一般用在页面权限验证,layout页面控制上,它们的执行次序是:
OnActionExecuting action执行前
OnActionExecuted action执行后
OnResultExecuting 页面渲染前
显示页面的内容
OnResultExecuted 页面渲染结果
如图所示
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAg8AAAFoCAIAAABfXo+KAAAgAElEQVR4nO2d749cxbnn/Tp/Am8r0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iHbb5hcioexdTCWOW2lzoyC2sev7L+gn8vrLFm3nUuRa7SREs32cXyUzDx7pm+ZD0pjPxJAwD0wzZjRGwbvuJqYe27NSym7YbqWO9SZKf9wXL75NOdbmoBg25ugsokML2RlB/PXMSXJScb/mQdHUItAGDcqeaXPyaQkT9pAIB+QC1QCwCAOKgFagEAEAe1QC0AAOIQOw8AAOKgFgAAEAe1AACAOKgFAADEQS0AACAOagEAAHFQCwAAiINaAABAHNQCAADioBYAABAHtQAAgDioBQAAxEEtAAAgDmoBAABxUAsAAIiDWgAAQBzUAgAA4qAWAAAQB7UAAIA4qAUAAMRBLQAAIA5qAQAAcVALAACIg1oAAEAc1AIAAOKgFgAAEAe1AACAOKgFAADEQS0AACAOagEAAHFQCwAAiPP/AYrB7nzb7JrNAAAAAElFTkSuQmCC" alt="" />
我们通过ActionFilterAttribute的特性,写个派生类,然后去覆写它的OnActionExecuted方法,将layout页面修改(注意是修改,因为在action执行之后layout已经是默认的布局页了)
代码如下:
/// <summary>
/// 自定义模板页面
/// </summary>
public class LayoutAttribute : ActionFilterAttribute
{
private readonly string _masterName;
public LayoutAttribute(string masterName)
{
_masterName = masterName;
}
/// <summary>
/// 页面渲染结束后执行
/// </summary>
/// <param name="filterContext"></param>
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
var result = filterContext.Result as ViewResult;
if (result != null)
{
result.MasterName = _masterName;
}
}
}
最后把它应用到controller或者action上,使用很简单
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYAAAAA+CAIAAACtEltZAAAG5ElEQVR4nO2dvY3CMBiGswRLwAqZgS4TZAMWSJ+OggnSpUG5AlFQUUV0SEigo6GgPAmJBXyFE/9+zoWDYALvIwrOOM6P4ofvM7EvYAAA4InA9wEAAD6XrgW0S4YBJ8pb1VWr5VHrbd+XPJKnf0nDbBCfWLEeDL7Sg9fjejSH9GsQnxhjrtPcJcNhsjO2EreI/RHoA08QkHlriHvGdIslIFGqF9ol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在控制器或Action上动态设定模板页(Layout)的更多相关文章
- MVC小系列(十六)【在控制器级别或具体Action级别上动态设定模板页(Layout)】
方法就是使用:ActionFilterAttribute它的几个方法:OnActionExecuted,OnActionExecuting,OnResultExecuted和OnResultExecu ...
- ASP.NET MVC3细嚼慢咽---(2)模板页
这一节演示下MVC3中怎样使用模板页,在传统的webform设计模式中,我们使用masterpage作为模板页,在MVC3 razor视图设计中,我们使用另一种方式作为模板页. 新建一个MVC3项目, ...
- WPF MVVM UI分离之《交互与数据分离》 基础才是重中之重~delegate里的Invoke和BeginInvoke 将不确定变为确定系列~目录(“机器最能证明一切”) 爱上MVC3系列~全局异常处理与异常日志 基础才是重中之重~lock和monitor的区别 将不确定变成确定~我想监视我的对象,如果是某个值,就叫另一些方法自动运行 将不确定变成确定~LINQ DBML模型可以对
WPF MVVM UI分离之<交互与数据分离> 在我们使用WPF过程中,不可避免并且超级喜欢使用MVVM框架. 那么,使用MVVM的出发点是视觉与业务逻辑分离,即UI与数据分离 诸如下 ...
- 第三章Struts2 Action中动态方法调用、通配符的使用
01.Struts 2基本结构 使用Struts2框架实现用登录的功能,使用struts2标签和ognl表达式简化了试图的开发,并且利用struts2提供的特性对输入的数据进行验证,以及访问Servl ...
- Struts2学习---基本配置,action,动态方法调用,action接收参数
首先我们先来直接配置,然后再来讲原理: 第一步:jar包的引入: 我们可以到struts2的官网上下载: http://struts.apache.org/download.cgi#struts251 ...
- .NET Core 反射获取所有控制器及方法上特定标签
.NET Core 反射获取所有控制器及方法上特定标签 有个需求,就是在. NET Core中,我们想在项目 启动时,获取LinCmsAuthorizeAttribute这个特性标签所有出现的地方,把 ...
- Struts2 Action中动态方法调用、通配符的使用
一.Struts2执行过程图: 二.struts2配置文件的加载顺序 struts-default.xml---struts-plugin.xml---struts.xml 具体步骤: 三.Actio ...
- (转载)VC/MFC 工具栏上动态添加组合框等控件的方法
引言 工具条作为大多数标准的Windows应用程序的 一个重要组成部分,使其成为促进人机界面友好的一个重要工具.通过工具条极大方便了用户对程序的操作,但是在由Microsoft Visual C++开 ...
- VC/MFC 工具栏上动态添加组合框等控件的方法
引言 工具条作为大多数标准的Windows应用程序的一个重要组成部分,使其成为促进人机界面友好的一个重要工具.通过工具条极大方便了用户对程序的操作,但是在由Microsoft Visual C++开发 ...
随机推荐
- angular之自定义过滤器的使用
自定义过滤器需要使用filter函数,格式如下: filter("filterName',function(){ return function(target,args){ .... } } ...
- 8天入门wpf(转)
8天入门wpf—— 第一天 基础概念介绍 8天入门wpf—— 第二天 xaml详解 8天入门wpf—— 第三天 样式 8天入门wpf—— 第四天 模板 8天入门wpf—— 第五天 数据绑定 8天入门w ...
- backbone框架思路
Backbone是MVC框架.如何使用这个框架来简化前端过程呢?作为一个初学者,虽然网上有它的官方文档,但是都是讲的一些方法,思路分析的却对初学者来说,看得晕乎乎的.现在就把自己对这个框架的理解记录在 ...
- 为Page添加INotifyPropertyChanged功能
在Page页面里面, DataContext 更新后,前台数据要求会自动更新. 但前台的绑定如果用x:bind 语法. 它要求强类型.直接关联到DataContext上就不行了. 需要为Page 添加 ...
- [Leetcode]Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. 这题貌似解法挺多,直接用简单的把数倒置,没有考虑数 ...
- C++内存对齐的理解
程序编译器对结构的存储的特殊处理确实提高CPU存储变量的速度,但是有时候也带来了一些麻烦,我们也屏蔽掉变量默认的对齐方式,自己可以设定变量的对齐方式. 编译器中提供了#pragma pack(n)来设 ...
- Unity3d中Update()方法的替身
在网上看到一些资料说Unity3d的Update方法是如何如何不好,影响性能.作为一个菜鸟,之前我还觉得挺好用的,完全没用什么影响性能的问题存在.现在发现确实有很大的问题,我习惯把一大堆检测判断放在U ...
- C++学习心得
从大一的学习中,我了解到C++是兼容C的面向过程和面向对象的程序设计语言.其中,面向对象程序设计方法是以对象为模板的结构化程序设计方法,是对结构化程序设计方法的继承和发展.刚开始的学习让我觉得特别吃力 ...
- 练习1-13:编写一个程序,打印输入中单词长度的直方图(水平)(C程序设计语言 第2版)
简单未考虑标点符号 #include <stdio.h> #define MAX_WORD_LEN 10 #define BLANK 0 #define IN_WORD 1 #define ...
- [ASE]项目介绍及项目跟进——TANK BATTLE·INFINITE
童年的记忆,大概是每周末和小伙伴们围坐在电视机前,在20来寸的电视机屏幕里守卫着这个至今都不知道是什么的白色大鸟. 当年被打爆的坦克数量估计也能绕地球个三两圈了吧. 十几年过去了,游戏从2D-3D,画 ...