Created
November 22, 2011 18:57
-
-
Save bernardobrezende/1386540 to your computer and use it in GitHub Desktop.
Manipulando ViewBag de dentro do Action Filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Mvc; | |
namespace Teste.TrocandoDadosComActionFilter.Controllers | |
{ | |
public class HomeController : Controller | |
{ | |
[MudaCor] | |
public ActionResult Index() | |
{ | |
ViewBag.Cor = "Welcome to ASP.NET MVC!"; | |
return View(); | |
} | |
public ActionResult About() | |
{ | |
return View(); | |
} | |
} | |
public class MudaCorAttribute : ActionFilterAttribute | |
{ | |
public override void OnActionExecuted(ActionExecutedContext filterContext) | |
{ | |
if (filterContext.Controller.ViewBag.Cor != null) | |
{ | |
filterContext.Controller.ViewBag.Cor = "Verde"; | |
} | |
base.OnActionExecuted(filterContext); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment