2017-02-15 7 views
0

私は2つのドロップダウンを1つ持っています(mutualExcParam)。それは3つのオプションがあります。このオプションを選択した場合は、別のドロップダウンを追加する必要があります(agencyRetrieve)。 これはJSONリクエストを介して行われ、少ないレコードでうまく動作します。レコードの読み込み時間が500を超える場合、読み込み時間が長くなります。私はループそれを通じて ..は、mvcの別のドロップダウン選択に基づいてドロップダウンオプションを設定します

$(document).ready(function() { 
$('.mutualExcParam').change(function() { // calling by class name on 1st dropdown 
    var agencyRetrieveId = $(this).attr('id') + '_'; // 2nd dropdown id 

    $.ajax({ 
     type: "POST", 
     contentType: 'application/json', 
     url: "../Report/FillAgencyValue", 
     data: JSON.stringify({ agencyId: agencyId}), 
     success: function (data) { 
      $('#' + agencyRetrieveId).html(''); 
      var optionhtml1 = '<option value="All">Select All</option>'; 
      $('#' + agencyRetrieveId).append(optionhtml1); 
      $(data).each(function() { 
      $('#' + agencyRetrieveId).append($("<option></option>").val(this.Value).html(this.Text));  
      }); 
      $(".selectpicker").selectpicker('refresh'); 
     } 
    }); 
}); 
}); 

[HttpPost] 
    public ActionResult FillAgencyValue(int agencyId, string fromDate, string toDate, int salesArea, string[] salesGroup) 
    { 
     AppCode.CommonCommands commonCommands = new AppCode.CommonCommands(); 

     PopulateControlData populateControlData = new PopulateControlData(); 
     // Get all Sales Area 
     DataTable dtsalesArea = commonCommands.GetAgencyDropdownData(agencyId, fromDate, toDate, salesArea, salesGroup); 

     populateControlData.agencyValues = new List<SelectListItem>(); 
     if (dtsalesArea.Rows.Count > 0) 
     { 

      populateControlData.agencyValues = (from DataRow row in dtsalesArea.Rows 
               select new SelectListItem 
               { 
                Text = row["ParameterLabel"].ToString(), 
                Value = row["ParameterValue"].ToString() 
               }).ToList(); 
     } 
     return Json(populateControlData.agencyValues, JsonRequestBehavior.AllowGet); 
    } 
+0

あなたの代わりに 'FillAgencyValue'からHTMLを返すことをお勧めします。 – Steve

+0

はい。コントローラーコードの平和も追加されました。 – Ammu

答えて

0

私はHTMLを返すようにコードを変更した際に影響を与えているパフォーマンスと同じ操作を行うための他の方法はあります。私はselect allオプションを含んでいませんでしたが、これはコントローラーメソッドのリターンの前に挿入するだけで追加できます。

私はコードをテストしていない、それは概念です。

$(document).ready(function() { 
$('.mutualExcParam').change(function() { // calling by class name on 1st dropdown 
    var agencyRetrieveId = $(this).attr('id') + '_'; // 2nd dropdown id 

    $.ajax({ 
     type: "POST", 
     contentType: 'application/json', 
     url: "../Report/FillAgencyValue", 
     data: { agencyId: agencyId}, 
     success: function (data) { 
      $('#' + agencyRetrieveId).empty(); 
      $('#' + agencyRetrieveId).html(data); 
     } 
    }); 
}); 
}); 

[HttpPost] 
public ActionResult FillAgencyValue(int agencyId, string fromDate, string toDate, int salesArea, string[] salesGroup) 
{ 
    AppCode.CommonCommands commonCommands = new AppCode.CommonCommands(); 

    PopulateControlData populateControlData = new PopulateControlData(); 
    // Get all Sales Area 
    DataTable dtsalesArea = commonCommands.GetAgencyDropdownData(agencyId, fromDate, toDate, salesArea, salesGroup); 

    List<string> lst = new List<string>(); 
    if (dtsalesArea.Rows.Count > 0) 
    { 

     lst = (from DataRow row in dtsalesArea.Rows 
       select new string.Format("<option value='{0}'>{1}</option>", row["ParameterValue"], row["ParameterLabel"])).ToList(); 
    } 
    return Content(string.Join(lst, "\n")); 
} 
+0

あなたの考えをお寄せいただきありがとうございます。 このデータを追加すると:JSON.stringify({agencyId:agencyId}) コントローラーメソッドFillAgencyValueにヒットするだけです。 コントローラーからの戻りリストの間に問題が発生しました – Ammu

+0

AJAX呼び出しでパラメータが予期され、定義されていないため、このメソッドを呼び出す際にエラーが発生する可能性が非常に高いです。たとえば、ブラウザの 'salesArea'デバッグ(F12)でこれが表示されます。 – Steve

+0

私はこのように渡します。 データ:JSON.stringify({agencyId:agencyId、fromDate:$( '#From-10'))val()、toDate:$( '#To-11')。 salesArea:$( '#Area_1')。val()})、 データを取得できます。ありがとうございました。 – Ammu

関連する問題