I have a problem with a ViewBag function pointer value being lost during a PostBack.
My site has a banner ( partial view ) where I indicate my customer’s status by utilizing a ViewBag function pointer:
ViewBag.CustomerStatus= new Func<id, string>(GetCustomerStatus);
(Where id is my customer’s id and returned string it’s returned status )
As I start going to other pages that utilize the banner partial view I loose my CustomerStatus ViewBag variable. I know ViewBags are only available “per page” but how can I make my Customer status function available from other places in the application without being redundant and repeating ViewBag.CustomerStatus= new Func(GetCustomerStatus); on every single ActionMethod call ?
Is it possible to have a function pointer stored in Session/ViewState? Safe ?
How can I access my up to date customer status across postbacks ?
Thank you in advance.
I ended up taking the following approach…
Instead of rendering partial view directly I changed it up so it’s called through an Action method of the controller.
I created:
So now instead of calling a ViewBag function pointer separately, whenever the header banner has to be rendered, instead of @Html.Partial(“BannerPartialView”) I call my @Html.Action(CustomerStatus) method that returns that same banner but with the customer status variable available.
Hope it’s not to confusing and helps to someone else.