Skip to content

Instantly share code, notes, and snippets.

@bernardobrezende
Created November 22, 2011 18:57
Show Gist options
  • Save bernardobrezende/1386540 to your computer and use it in GitHub Desktop.
Save bernardobrezende/1386540 to your computer and use it in GitHub Desktop.
Manipulando ViewBag de dentro do Action Filter
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