Some time we need to access the common Properties in every view. Suppose we have to access the user additional information. So we have create controller base class as example is given below
public class BaseController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
ViewBag.UserInfo = "someThing"; //Add whatever
base.OnActionExecuting(filterContext);
}
}
// inherit HomeController to base classs
public class HomeController : BaseController
{
public ActionResult Index()
{
ShoppingCartViewModel obj = new ShoppingCartViewModel();
return View(obj);
}
No comments:
Post a Comment