Tri*_*oan 2 c# asp.net asp.net-mvc-3
正如您所知,在WebForm中触发事件非常容易,但这是MVC框架中的一个问题.例如,我有2个DropDownList,Country和State.我想State在所选的基础上加载数据Country.在WebForm中,我可以触发SelectedIndexChange事件,但在MVC框架中,我该怎么办?
请帮忙.提前致谢.
在WebForm中,我可以触发SelectedIndexChange事件,但在MVC框架中,我该怎么办?
您可以使用javascript并订阅onchange下拉列表的javascript事件.
例如,如果您使用jQuery:
<script type="text/javascript">
$(function() {
$('#id_of_your_drop_down').on('change', function() {
// the value of the dropdown changed. Here you could do whatever
// you intended to do. For example you could send the selected value
// to a controller action using an AJAX call.
var selectedValue = $(this).val();
var url = '@Url.Action("SomeAction")';
$.post(url, { value: selectedValue }, function(result) {
// The AJAX request completed successfully. Here you could
// do something with the results returned by the server
});
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1447 次 |
| 最近记录: |