far_loner
far_loner

Reputation: 103

Cascading drop down list Data source

My team is working on a web application using MVC4 with .NET 4.5. One task is to create a parent drop down list that will update a child drop down list when a value is selected in the parent - for example a drop down list of states would filter a drop down list of cities when a state is selected.

On our other projects we use Ajax calls to a web service or database to populate the values of a child when a parent value is selected. In my example above, the state of Minnesota is selected, and an Ajax call is made to the database to grab all cities in MN. I have read other posts on here and tutorials that follow this concept.

A new developer on our team believe the method above is inefficient and it is better to grab all cities on page load, store the cities as a Jason object in a JavaScript variable and then use jquery to loop through the JavaScript variable and build the child list.

Can someone give me feedback on which method they have used? I don't believe pulling thousands of records into the browser and storing on the client is very efficient when we may only show 10 of the records. This developer also believes looping through a 10000 row JSON object in JavaScript is faster than making a database call to grab 10 rows.

Upvotes: 5

Views: 663

Answers (1)

Sam
Sam

Reputation: 113

Create your list and you can call everything from LINQ. Check the cache to create from there before you do your other calls to instantiate

public IList<Example> GetList(string _state)
{

    IList<Example> cities = new List<Example>();

    Cache cache = HttpContext.Current.Cache;

    if (cache[_state] != null)
        cities = (IList<Example>)cache[_state];

    else
    {
        //Do your calls
        cache.Insert(_state, cities);
    }

    return cities;
}

Upvotes: 1

Related Questions