繁体   English   中英

当DropDownListFor项目更改为ASP.Net MVC时执行脚本

[英]Execute script when DropDownListFor item changed ASP.Net MVC

我有一个DropDownListFor这样的:

    <div class="drop-down-list">
        <%: Html.DropDownListFor(model => model.StageId, ViewBag.StagesList as SelectList,new { @id="stageOne"})%>
        <%: Html.ValidationMessageFor(model => model.StageId) %>
    </div>

当选定的项目更改时,我需要触发类似下面的代码才能进入控制器,填充一个视图包并填充另一个DropDownListFor。 实际上,我想在asp.net mvc中构建两个级联的DropDownListFor。

  <script>
    $('#stageOne').change(function () {
        $.ajax({
            url: '/Shop/ChangeStageTwo/',
            data: { item: $("#drop-down-list").sortable('toString') },
            type: 'post',
            traditional: true 
        });

    });
  </script>

但是,当用户更改第一个DropDownListFor时,什么也没有发生。 问题是什么?? 非常感谢。

就像Michael_B所说的那样,我将代码更改为此,问题得以解决:

 $(function () {
   $('#stageOne').change(function () {
        $.ajax({
            url: '/Shop/ChangeStageTwo/',
            data: { item: $("#drop-down-list").sortable('toString') },
            type: 'post',
            traditional: true 
        });

    });
 });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM