Asp.net mvc 3 MVC3在下拉选择时调用控制器功能

Asp.net mvc 3 MVC3在下拉选择时调用控制器功能,asp.net-mvc-3,Asp.net Mvc 3,我在局部视图中有以下代码 Country Selector</label> @Html.DropDownListFor(model => model.CountryGroup, Model.CountryCodes, new { id = "CountryGroup", name = "country-codes" }) @Html.ValidationMessageFor(model => model.CountryGroup, "*") 我假设当代码

我在局部视图中有以下代码

Country Selector</label>
    @Html.DropDownListFor(model => model.CountryGroup, Model.CountryCodes, new { id = "CountryGroup", name = "country-codes" })
    @Html.ValidationMessageFor(model => model.CountryGroup, "*")
我假设当代码运行时,var上的断点将被命中。事实并非如此。 有人能告诉我在哪里可以找到控制器中运行函数的方法吗


thnx

如果要在从下拉列表中选择项目时调用控制器操作,则需要侦听下拉列表中的
更改
事件,并使用jQuery ajax调用操作方法

$(function(){
  $("#CountryGroup").change(function(){
     $.get("@Url.Action("ProcessRemoteOrder","YourControllerName")",
                                                                  function(data){
         //do some thing with the response, in data variable.
     });
  });
});

检查它是否正在运行。在代码中要调试的行上设置一个断点,当代码执行该行时,断点将以黄色突出显示。

感谢您的回答。因此,我在别处看到了这一点,并尝试了它。我在控制器函数中有断点,即使页面重新加载,它也不会被命中。是否应点击断点?页面不会在下拉项select上重新加载。如果发生这种情况,还有其他脚本在这样做。在您的页面中检查它,因此我在Js**$.get('@Url.Action(“ProcessRemoteOrder”,“Checkout”)'中有这个,但它呈现为**$.get(“”,-我应该看不到get中呈现的url吗?如果它是外部js文件,则不能使用url帮助器方法。您需要在razor视图文件的全局js变量中使用帮助器方法获取这些路径,并在外部javascript中使用这些变量
$(function(){
  $("#CountryGroup").change(function(){
     $.get("@Url.Action("ProcessRemoteOrder","YourControllerName")",
                                                                  function(data){
         //do some thing with the response, in data variable.
     });
  });
});