下拉值到ActionLink

时间:2015-01-02 00:46:20

标签: jquery ajax asp.net-mvc asp.net-mvc-3

我需要获取下拉列表选择的值才能在同一个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>

1 个答案:

答案 0 :(得分:0)

@Html.ActionLink("Order New", "View","Home",null, new { @id = "viewLink" })

即使在此链接上听取点击,并阅读下拉列表的选定值,构建用于加载部分视图的URL用户/导航到该

$(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;
  });

});