views:

451

answers:

2

Hi all,

I'm studing Microsoft ASP MVC framework. Here is a problem I encounterd: I have a view with DropDownList containning a list of countries and another DropDownList for states. The OnChange event post the form back and then the controller sends data to the states drop down which should update. But the second DropDownList doesn't change. They stay as what it was before the refresh. What should I do to fix this.

Thanks in advance!

Edit: Call ModelState.Clear() in the second controller fix that problem. Thanks for all of you who offers suggestions! Really Thanks!

+2  A: 

ASP.Net MVC provides a new mechanism for generating dynamic web pages. It is at a much lower level of abstraction than ASP.Net and as a result familiar features of ASP.Net like events are deliberately not supported.

Try reading this blog entry for an example of how to do what you want on the client side using JQuery. This fits nicely into the MVC approach

MikeD
Thanks Mike. I'll have a try later!
Roy
I can't access to blogspot now, but I've seen what does Stephen Walther do(http://stephenwalther.com/blog/archive/2008/09/07/asp-net-mvc-tip-41-creating-cascading-dropdown-lists-with-ajax.aspx).But there is still some problems. I also what to add a text box showing something related to the country. They still have the problem as described in the question. I also what to know why this happens on ASP.net MVC? And what should I do to change this behavior of MVC? Thanks!
Roy
Can you post your code so I can see what you are trying to do?
MikeD
@Roy :) you didn't need to open a new question to provide more info, but I guess that you have found that out by now!
MikeD
A: 

ASP.NET MVC is able to return a JSON format result, what you need to do then is just calling that Controller's Action via jQuery and then display the drop down. you can see the details here - http://setiabud.blogspot.com/2009/05/cascading-drop-down-with-aspnet-mvc.html

Sachin
I think you misunderstood the question.
çağdaş