Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Razor dynamic drop down helper
@helper DynamicDropDowns() {
<script type="text/javascript">
function listChanged($list, $target, url) {
var listId = $list.val();
if (listId == "") { // User selected first option, so clear and disable the list
enableList($target, false);
$.getJSON(url, { id: listId }, function (data) {
$target.empty(); // Clear the list
$.each(data, function (idx, item) { // Add the data
value: item.Value,
text: item.Text
enableList($target, true); // Enable the list
function enableList($list, enabled) {
$list.attr("disabled", enabled ? null : "disabled");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment