1

I have an ActionResult that sets TempData to be an object.

The page that is rendered contains a button, that launches a JSON request to the same controller. (For jqGrid population).

The TempData on the JSON Request is null - why does this happen?

Even more bizarrely, if I had a button that posts to the same controller, and I click it instead of my JSON request button, TempData will be there, but if I click the JSON button, then the post button, TempData will be null.

Help appreciated.

Thanks, Chris

2
  • Do you have any code samples you could show us? Commented Aug 19, 2009 at 15:49
  • I agree with James, we need to see code here. Commented Aug 19, 2009 at 15:56

1 Answer 1

6

Do not try to pass data from one action to another via TempData when not redirecting. TempData is only for redirects. It is quite likely that some other element of your page is making a request before you press the button, causing the items you've squirreled away in TempData to vanish. That's why TempData is for redirects only; only when redirecting can you have any confidence at all of what the next request will be.

Instead, put the data in the rendered page. When you need to request an action that needs this data, pass it explicitly as a query string parameter.

HTTP is stateless. Learn to live with that. Don't try to introduce state to your server; you'll regret it if you do.

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

Comments

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.