1

In ASP.Net MVC passing the object and model is safe and easy to implement, and passing value via QueryString in webform is simple too.

What is the best way to pass objects to another page?

2
  • When you say object, you mean model? Its gets passed in by the controller. If you need multiple models or additional info then you need to create a viewmodel with that information. Commented Dec 7, 2013 at 7:22
  • i want to pass in webforms , not in MVC . Commented Dec 7, 2013 at 7:23

1 Answer 1

2

The object you want to pass can be saved in a session or the cache and then retrieved from some other page.

  1. Page 1: Save object to session with an identifier using the code: Session["SomeIdentifier"] = myObjectInstance;
  2. Move to Page 2
  3. Page 2: Retrieve object from session using the identifier using the code: var myObjectInstance = (MyObjectInstance) Session["SomeIdentifier"];

Or you can replace Session (which is persistent) by using Context.Items["MyObjectInstance"] (removed after a request), see my comment for the difference between the two.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks, how about Context.Items["object"] for passing object ?
Depends on your requirements. Context.Items lifecyle ends after each http request so once the request is done, the contents are no longer in memory unlike session items. So if you need the object multiple times on different pages, use session, if you only need to retrieve it once, use context.
aha , so if you see Context.Items["object"] one way, add in your answer too. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.