2017-04-24 8 views
-1

ドロップダウンリストでデータベースを分類するにはどうすればいいですかカテゴリのサブカテゴリを知る方法ドロップダウン選択?

私はINVORGカテゴリをクリックしてDEPTCODEで表示しますか?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<script type="text/javascript"> 
 
    $(document).ready(function() { 
 
     //Dropdownlist Selectedchange event 
 
     $("#INVORG").change(function() { 
 
      $("#DEPTCODE").empty(); 
 
      $.ajax({ 
 
       type: 'POST', 
 
       url: '@Url.Action("GetDEPTCODE")', // we are calling json method 
 
       dataType: 'json', 
 
       data: { id: $("#INVORG").val() }, 
 
       // here we are get value of selected INVORG and passing same value 
 
       success: function (states) { 
 
        // states contains the JSON formatted list 
 
        // of states passed from the controller 
 
        $.each(states, function (i, state) { 
 
         $("#DEPTCODE").append('<option value="' + state.Value + '">' + 
 
         state.Text + '</option>'); 
 
         // here we are adding option for States 
 
        }); 
 
       }, 
 
       error: function (ex) { 
 
        alert('Failed to retrieve states.' + ex); 
 
       } 
 
      }); 
 
      return false; 
 
     }) 
 
    }); 
 
</script>
HTTPGETにあなたの方法は、データを取得しているよう

答えて

0

変更

using Json 
 

 
[HttpPost] 
 
     public JsonResult GetDEPTCODE(string id) 
 
     { 
 
      List<SelectListItem> states = new List<SelectListItem>(); 
 
      /// 
 

 
//I got Error Code, can you please define my wrong code and correct thanks 
 

 
      states = from u in _db.USERGROUPs where u.INVORG == id 
 
        select(new SelectListItem {Text =u.INVORG, Value = u.DEPTCODE}); 
 

 

 
     return Json(new SelectList(states, "Value", "Text")); 
 
     }

[HttpGet] 
    public ActionResult GetDEPTCODE(string id) 
    { 
     List<SelectListItem> items= new List<SelectListItem>(); 
     return Json(new { data = items}, JsonRequestBehavior.AllowGet); 
    } 

変更以下のようにスクリプト

$("#INVORG").change(function() { 
     $("#DEPTCODE").empty(); 
     $.ajax({ 
      type: 'GET', 
      url: '@Url.Action("GetDEPTCODE")', // we are calling json method 
      dataType: 'json', 
      data: { id: $("#INVORG").val() }, 
      // here we are get value of selected INVORG and passing same value 
      success: function (data) { 
       // states contains the JSON formatted list 
       // of states passed from the controller 
       $("#DEPTCODE").html(''); 
       $.each(data["data"], function (key, value) { 

       $("#DEPTCODE").append($("<option> 
     </option>").val(value.Value).html(value.Text)); 

      }); 
      }, 
      error: function (ex) { 
       alert('Failed to retrieve states.' + ex); 
      } 
     }); 
     return false; 
    }) 
+0

こんにちは先生 –

+0

は、この[リンク]を参照してください表示されませんinvorgの下で動作しませんでしたあなたのコード、(https://dotnetfiddle.net/1bPZym) – Learner

+0

この回答はあなたの元の質問に投稿されました。あなたは全体の質問を変更できますか? @ThePrograMMER – Learner

関連する問題