How to set values to ViewBag in ActionFilterAttribute ASP MVC 5?

You can do like this

public class SomeMsgAttribute : FilterAttribute, IResultFilter
{
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
        }

        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            filterContext.Controller.ViewBag.Msg= "Hello";
        }
}

Using:

[SomeMsg]
public ActionResult Index()
{
    return View();
}

Leave a Comment

deneme bonusu veren sitelerbahis casino