0

The controller in which I define a viewbag value, returns a partial view, which is the last view that is beinng returned.

This partial view is rendered to a JQuery dialog. After I close it, I return to the one before, which contains a form. In the form view (the one before the last one) I'm trying to access the viewbag value via JS function, and assign it to a hidden field in the form. So actually, I'm trying to get the viewbag value, not from the view to which I've sent the viewbag.

Is it a problem? Are viewbag values available only from the last view that has rendered?

Tal l
  • 265
  • 1
  • 3
  • 12
  • Actually: http://stackoverflow.com/questions/10269975/cant-pull-data-out-of-viewbag-in-mvc – Tal l Apr 22 '12 at 18:09

1 Answers1

1

I'm not sure if it's possible, but in any case you wouldn't normally want or need to access ViewBag outside of the view it belongs to. It seems like there would be a couple of better options.

Community
  • 1
  • 1
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
  • tnks for your time! I've considered these options. Using the dialog callback is not practical, since I need the value as soon as I close the dialog. I would very much want to have an answer for my question. – Tal l Apr 22 '12 at 18:41
  • @Tall that doesn't make sense to me ... you said you're running some JS to access the value, right? So why don't you pass a JS function containing that code as the callback to your JQ dialog? – McGarnagle Apr 22 '12 at 18:55
  • I've checked one more, and there's indeed a 'beforeClose' event. My mistake - I intend to use it. Despite my wish to get a definite answer to my question, I'll mark your comment as an answer. – Tal l Apr 22 '12 at 19:04