Populating dropdown with JSON result - Cascading DropDown using MVC3, JQuery, Ajax, JSON

后端 未结 8 1770
长发绾君心
长发绾君心 2020-12-03 11:10

I\'ve got a cascading drop-drown using mvc. Something like, if you select a country in the first-dropdown, the states of that country in the second one should be populated a

8条回答
  •  死守一世寂寞
    2020-12-03 12:14

    You should consider using some client-side view engine that binds a model (in your case JSON returned from API) to template (HTML code for SELECT). Angular and React might be to complex for this use case, but JQuery view engine enables you to easily load JSON model into template using MVC-like approach:

     
    

    It is much cleaner that generating raw HTML in JavaScript. See details here: https://jocapc.github.io/jquery-view-engine/docs/ajax-dropdown

提交回复
热议问题