views:

297

answers:

2

HOw can i change content of ViewData on drop down list change using javascript in MVC View?

A: 

If I'm not wrong you cannot change from client the server side object that is alive only during page rendering. You could change ViewData object of one page by putting there other data in controller.

Jenea
A: 

Short answer is: you can't.

Even if you could, nothing would happen Because you'd need to render your view with the new ViewData.

Javascript runs client side. That means, the user's computer.

ViewData is a server side collection. It is a data transfer object between your controller and view, which stays on your server.

You need to change the way you think. You can either make the change you want with javascript on client's comptuer when drop down changes, or you can post the value in drop down list and render the view with the new data, and send back to client.

Serhat Özgel