We are building an MVC4 Intranet app. One of the features we would like to offer is to have the user select a company on which they would like to operate so that the data displayed is specific to the selected company (similar to how the user information
is persisted once they are logged in).
We'd like to include a company selector (drop-down list) as part of our _Layout.cshtml file so it is available from any page.
We are having some challenges finding methods other than using a session variable or cookie to persist the selected company, which would require us to check this information from every action in our controllers.
Can anyone please suggest an alternative along with some examples? We have been hard-pressed to find anything remotely close to what we're trying to achieve.
We are having some challenges finding methods other than using a session variable or cookie to persist the selected company, which would require us to check this information from every action in our controllers.
Cookie is the best option for this type of functionality.
sking_coins
Member
1 Points
7 Posts
Persisting data from view to view
Dec 06, 2012 12:26 AM|LINK
We are building an MVC4 Intranet app. One of the features we would like to offer is to have the user select a company on which they would like to operate so that the data displayed is specific to the selected company (similar to how the user information is persisted once they are logged in).
We'd like to include a company selector (drop-down list) as part of our _Layout.cshtml file so it is available from any page.
We are having some challenges finding methods other than using a session variable or cookie to persist the selected company, which would require us to check this information from every action in our controllers.
Can anyone please suggest an alternative along with some examples? We have been hard-pressed to find anything remotely close to what we're trying to achieve.
Thank you.
ignatandrei
All-Star
134491 Points
21566 Posts
Moderator
MVP
Re: Persisting data from view to view
Dec 06, 2012 01:51 AM|LINK
Make a base controller for that.
CPrakash82
All-Star
18154 Points
2831 Posts
Re: Persisting data from view to view
Dec 07, 2012 12:31 AM|LINK
Cookie is the best option for this type of functionality.
fiftytrini
Member
117 Points
18 Posts
Re: Persisting data from view to view
Dec 07, 2012 01:49 AM|LINK
I agree with @ignatandrei. A base controller in MVC or a base web page in web forms are great ways to implement this.
sr. application systems analyst
please "Mark As Answer" if this post answers your question or addresses your issue.
Xequence
Contributor
4303 Points
1528 Posts
Re: Persisting data from view to view
Dec 07, 2012 02:20 AM|LINK
i agree base class derived class is an abstract approach to this and makes sense.
but there is an action filter... which i find to make sense but have not performed maintenance on it yet...
http://odetocode.com/Blogs/scott/archive/2010/06/28/action-filter-versus-controller-base-class.aspx
Credentials
sking_coins
Member
1 Points
7 Posts
Re: Persisting data from view to view
Dec 07, 2012 04:27 PM|LINK
Thank you all for your suggestions!