-1
我怎样才能在数据库uisng下拉列表分类的onces如何知道类别下拉选择的子类别?
我点击INVORG类别,并显示在可用DEPTCODE?
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"));
}
<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>
先生你好你的代码没有工作,invorg下不会出现 –
看到这个[链接](https://dotnetfiddle.net/1bPZym) – Learner
这个答案是张贴为您原来的问题..你可以改变整个问题? @ThePrograMMER – Learner