ポール、あなたはこの関数をどこで呼んでいますか? これを document.ready 関数内で呼び出す必要があると思います。
また、選択した値でモデルをバインドする必要があります。html で利用できるようにします。ポストバックはありません。データを送信すると、セッション管理はありません。応答は、コントローラーから作成したモデルに基づく新しいページになります。
応答後またはポストバックでスクリプトが実行されていないと思われます。確認してください。ajax の読み込みまたはスクリプトが実行されていないため、html に値が含まれていません。指定したスクリプトが機能していることを確認してください。
ドキュメントを準備して質問を更新してください。
編集
$("#ddlBrand1").change(function () { //this will trigger only when ddlBrand1 changes
$.getJSON("URL", { id: idBrand },
function (carModelData) {
// check this line of code executes ?
// alert(carModelData) may expected to return some thing
// other than null
$("#ddlModel1").removeAttr('disabled');
// makes ddlModel1 active
var select = $("#ddlModel1");
select.empty();
// clears the items of #ddlModel1
select.append($('<option/>', { value: '', text: "---Select Model---" }));
// adds new --Select-- (you can give value as 0)
$.each(carModelData, function (index, itemData) {
select.append($('<option/>').val(itemData.Value).html(itemData.Text ));
});
// this will loops the JSON result from the server and
adds the option (items)
});
});
トラブルシューティングのテクニック
1.This function will call only when 'ddlBrand1' changes. For this to
happen ddlBrand1 needs to have more than one option.
2. Check whether getJSON returns a proper value.
3. Verify the url,parameters and the result (here carModelData). Alert it.
4. Also verify the response from server is not null.
You need to verify the controller, action etc. An error occurred in controller
also leads to same issue.
5. Refer this below and add .error,.sucess,.complete
jQuery 1.5 の Promise インターフェースでは、$.getJSON() を含む jQuery の Ajax メソッドを使用して、複数の .success()、.complete()、および .error() コールバックを単一のリクエストで連鎖させたり、後でこれらのコールバックを割り当てたりすることもできます。リクエストが完了した可能性があります。リクエストがすでに完了している場合は、コールバックがすぐに開始されます。ここをクリックURL