ASP.NET MVC3 app (part 2) – ajax cascading dropdown

Written by  on June 9, 2011 

 

To make cascading dropdowns in application from part 1, I created ProductFilter:

image

I will use this class as model for my home controller Index method:

image

Here you can also see Manufacturers JsonResult method, which is used for asynchronous refresh of second dropdown:

imageimage

Manufacturer dropdown is loaded with manufacturers which produce models of chosen product type. This is made possible with simple jquery function:

image

This function accepts url of method which provides json list of items for dropdown, passes formData parameter with id, and places results into target for which selector “target” is provided.

This is how my view from which this method is called looks:

image

Two dropdowns are created using standard MVC helpers, and onchange event function is attached using jquery. More dropdowns can be chained in the same way, there is only necessary to add change function in the same manner. However, this is no good, as event attachment is manual, and script must be written, and included into view as selectors are generated here. My goal is to make these event attachments unobtrusive, and I will write about that in part 3.

For now, you can download project source code here.

Back to part 1

Comments

4 Responses

  1. pthalacker says:

    Can’t wait for part 3

  2. [...] Take my work with me ASP.NET MVC3 app (part 2) – ajax cascading dropdown [...]

  3. ASP.NET MVC3 app (part 2) – ajax cascading dropdown | Goran Obradovic’s blog…

    Thank you for submitting this cool story – Trackback from Blue Ray Plus – Latest Technology News…

Leave a Reply

%d bloggers like this: