Bind DropDownlists with JQuery in Asp.Net -


There is a 3 dropdown list for my country, state and metro. I want that when the user country then fill in the state drop downdown, select Jquery and when Sate and then press the Metro dropdown Fill in the list (like AJAX's Cascading dropdown list). I want to do this process with JQuery.

I am going to describe it in ASP.NET MVC, but if you are either ASP.NET Write a web service or put some page methods in your code to be followed, you can get it - you should also need a JSON serializer, either party solution at third number or one in WCF.

To use the first MVC, perform three controlling actions - To display a page, the country will be static, and to get states and metros respectively, two:

Public Performance Index () {View Data ["country"] = _countryRepository.GetList (); See Return (); } Public Action State (string country code) {var states = _stateRepository.GetList (countryCode); Back Jason (state); } Public Performance Metres (string countrycode, string state) {var metros = _metroRepository.GetList (country code, state); Return Jason (Metro); }

In this view, you have three dropdown lists, a viewdata ["country"] is bound to the object, it says that its name is country, with an Ajax call Can find the state in jQuery. Like this:

  $ ('# country'). Change (function () {var val = $ (this) .val (); $ states = $ ('# states'); $ .aex ({url:' & lt;% = Url.Action ('state') % & Gt; ', Datatype:' Jason ', Data: {Country Code: Well}, Success: Work (state) {$ .each (states, work (i, state) {$ states.append (' & lt; Option value = "'state. Abb ++" "> state + name +'  gt; ')}}}}, error: work () {warnings (' failed to retrieve states .);}}};});  

Metros drop down will be completely filled, both countries and states will be selected from the server and the metro areas Withdrawing a JSON object with an array of.

I left the details of the repository implementation, just fill out the result variables on the server with a collection of metro areas on the server. I also created a notion That the state class will have two assets in ABbr (e.g. 'ca') and name (for example, California).

I hope that this helps you in any way, or less Less than you Is directed toward Madhan.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -