I have an ASP.NET MVC3 project that uses a tab strip on certain pages. The tab stop is constructed in JavaScript. When the user performs action I would like to be able to redirect them to the correct page with the correct tab open. To achieve this I either need to pass a variable in the URL and get a handle on it using JavaScript or pass a variable back using the ViewBag or TempData and again, get a handle on it using JavaScript.
So my question is, how can I access these variables using JavaScript?
You could pass the value as query string parameter when redirecting and in the target action simply define a view model:
and then have an anchor or a controller action that will redirect to the target action and pass
myvalueas query string parameter:and when the link is clicked the user gets redirected to the Foo action which takes the view model as argument so that the binding happens automatically and passes this view model to the corresponding view:
and in the corresponding view you could do whatever you want with the view model: