ActionLink 的下拉值

Dropdown Value to ActionLink

我需要获取下拉列表的选定值才能在同一个 PartialView 中使用它:

@Html.DropDownListFor(model => model.ModelType, new SelectList(Model.infoModel, "idModele", "nomModel"), new { id = "ModelType" })

我需要 ModelType 的值来代替 2:

  @Html.ActionLink("Order New", "View", new { id = 2 }, new { @class = "viewDialog" })

我试过了,但没用我更喜欢通过下拉值更改 2 的方法:

 <input class="btn btn-primary" type="button" value="badd" id="badd">

在我的文件末尾添加:

 <script>
  $('#badd').click(function (e) {
      e.preventDefault();
      window.location.replace =
      '<%=Url.Action("Order New","View", "Home")%>' + '?id=' + $('#ModelType').val();
  });
 </script>
@Html.ActionLink("Order New", "View","Home",null, new { @id = "viewLink" })

甚至在这个 link 上听点击,并读取下拉列表的选定值,构建 url 使用它来加载你的部分 view/navigate 到

$(function(){

  $(document).on("click","#viewLink",function(e){
     e.preventDefault();

     var newUrl="@Url.Action("View","Home")?id="+$("#ModelType").val();
     // you can do whatever you want with the new url 
     //  window.location.href=newUrl;
  });

});