Monday 5 August 2013

Cascading DropdownList feature in MVC4 and Razor

Models which are used in our example.
A) Subjects
B) Students

A controller method for filter is as shown below.
Here it will take the selected value of Subjects .DropdownList as argument and Return filtered in Json format.

On the other side in View page I have something like below.

Parent DropdownList:

Child DropdownList:

Jquery Call  to get Filer Data and bind Child DropdownList
 
Below are the Pron and Cons of the approach.  

Pron:
A) Because of Ajax, it won’t load whole page instead it will load that particular DropdownList only.

B) Light weight.  

Cons:
A) Bit complex than normal binding of DropdownList.

B) We cant have intelligence for the value return in Jason format.