better way to load 2 dropdown in mvc

后端 未结 5 785
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 03:05

This is how i am loading on page load state and city dropdown:

My Controller method:

This is the first method which is calling when page is

5条回答
  •  清歌不尽
    2020-11-22 03:30

    disclaimer: This is not a code answer, there are plenty other answers.

    I think best way to keep yourself happy to seperate UI pages from data => turn them into API calls:

    • /GetCities
    • /GetStates

    Now you can simply leave the select's empty on Razor rendering the page. And use a Jquery/Bootstrap plugin to create an AJAX select box.

    This way when the user stops typing his search, this search string can than be send with the AJAX call (eg: /GetStates?search=test) and then a small result set can be send back to the website.

    This gives:

    • Better separation in serveside code
    • Better User eXperience.
    • Smaller page loads (since you no longer send all the options to user when he requests the page, only when he opens the select box).

提交回复
热议问题