Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi to all,
Here i have dropdown for state and city using model. but now i want populate city as per state selection.Can anybody help me.Here im using linq so kindly help me Here im using database table

Description:-
For state Stateid ->Primarykey,statename

For city Cityid->primary key, City-name , StateId->foreign key

Can anybody help me how to populate city as per state name using LINQ
Posted

1 solution

Now you can to that, by making an ajax call. Now your states dropdown gets all the items(state names), so when the user selects the state you can get the value of that field{provide an id to @Html.DropdownListFor()}if you are using razor and get the value. On select of the state make an ajax call in your java script passing the state value as parameter and write the linq to get all the cities for the states.
Here the stateId needs to be a foreign key in the cities table. So that your query may go like this:- var cities = context.Cities.Where(c=>c.StatesId==stateId)[stateId is the parameter that is passed in the ajax call]

hope you uderstood.
Thank you
:)
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 12-Aug-14 1:57am    
can you explain deeply ajax call script code like this because im new for mvc so kindly teach me as well i understood
[no name] 12-Aug-14 9:53am    
ya sure why not.
see i guess you know providing id to the dropdownList and using that id you get the value?
JOTHI KUMAR Member 10918227 13-Aug-14 1:21am    
can anybody help me for that
JOTHI KUMAR Member 10918227 13-Aug-14 1:26am    
here i what procedure i call in controller and partial view to populate the city and state

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900