ShowMessageAttribute.cs
namespace MvcApplicationEmpty.Attributes { public class ShowMessageAttribute : ActionFilterAttribute { public string Message { get; set; } public override void OnActionExecuting(ActionExecutingContext filterContext) { //base.OnActionExecuting(filterContext); filterContext.HttpContext.Response.Write("[OnActionExecuting " + Message + "]"); } public override void OnActionExecuted(ActionExecutedContext filterContext) { //base.OnActionExecuted(filterContext); filterContext.HttpContext.Response.Write("[OnActionExecuted " + Message + "]"); } public override void OnResultExecuting(ResultExecutingContext filterContext) { //base.OnResultExecuting(filterContext); filterContext.HttpContext.Response.Write("[OnResultExecuting " + Message + "]"); } public override void OnResultExecuted(ResultExecutedContext filterContext) { //base.OnResultExecuted(filterContext); filterContext.HttpContext.Response.Write("[OnResultExecuted " + Message + "]"); } } }
XXXXController.cs
... [ShowMessage(Message="Koma")] public ViewResult Default() { ViewData["greeting"] = "from HomeController.Default"; return View(); } ...
出力結果:
[OnActionExecuting Koma][OnActionExecuted Koma][OnResultExecuting Koma]
Home.Default from HomeController.Default
[OnResultExecuted Koma]
0 件のコメント:
コメントを投稿