Search code examples
c#.netasp.net-mvc-3entity-framework-4

what is the scope of Viewbag in mvc3 and how do we maintain state in MVC


  1. what is the scope of Viewbag in mvc3 is it only available on the page we are rendering through my action method.
  2. How do we maintain information across the page in MVC. Suppose i Create new employee and and when I move to next page I want that employee information.
  3. How do we maintain state in MVC.

Solution

    1. the view bag is part of the httpcontext. it's primarily set in the controller action and read in the view, but it can be accessed from just about anywhere in the mvc framework within an http request/response.
    2. the web does not have state, like you would in a rich client app. To maintain values from page to page (or more appropriately, request to request) you can use cookies, session, query string, the request body (think post/put requests).
    3. same as #2.