javascript - 如何在下拉列表更改时自动点击ActionLink?

标签 javascript asp.net-mvc

我有一个下拉菜单和一个操作链接。 当下拉列表更改时,将自动单击此操作链接。怎么做?。下面是我的代码,谢谢。

   @Html.DropDownListFor(model => model.PaymentCode, (List<SelectListItem>)ViewBag.JenisPembayarans, new { @class = "form-control" })
   @Html.ActionLink(
                       "Detail",
                       "GetInsuranceCompany","ParamBlacklistPembayaran",
                       new { id = Model.PaymentCode }, new { @class = "ddlSubmit"})

Controller

public ActionResult GetInsuranceCompany( ParamBlacklistPembayaranViewModel model,string id)
{ 
  LoadThirdPartyDDL(string.Empty, string.Empty, id);
  return View("Create", model);
}

最佳答案

 @Html.DropDownListFor(model => model.PaymentCode, (List<SelectListItem>)ViewBag.JenisPembayarans, new { @class = "form-control",@id="ddl" })


@Html.ActionLink("Detail",
                       "GetInsuranceCompany","ParamBlacklistPembayaran",
                       new { id = "PaymentCodeVal" }, new { @id="anchorclick",@class = "ddlSubmit"})

您应该像这样调用下拉更改的点击事件:

 <script>
        document.getElementById('ddl').onchange = function () {
         var  path =  document.getElementById('anchorclick').href;
                      path = path.replace("PaymentCodeVal", document.getElementById('ddl').value);
                      document.getElementById("anchorclick").href=path; 
                      document.getElementById('anchorclick').click();
    };
 </script>

@注意:您想要获取更新的 PaymentCode。您必须注入(inject) url 以在更改事件上传递 PaymentCode。

关于javascript - 如何在下拉列表更改时自动点击ActionLink?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56214144/

相关文章:

javascript - 导航到另一个页面时,Mootools 弹出窗口不会保持关闭状态

javascript - NoUIslider - 按需更新范围

javascript - Dynamics CRM 2011 - 更改相关实体列表的 View

asp.net-mvc - 控制台/Web App 解决方案上的 Hangfire 作业?

asp.net-mvc - asp.net/MVC 自定义模型验证属性不起作用

c# - .net开发代码结构-Controllers, Services, Repositories & Contexts

javascript - 通过另一个数据属性作为标识符获取元素的数据属性

javascript - Javascript 中的 function name() 和 name = function() 有什么区别?

c# - 在 C# 中使用 SmtpClient 发送电子邮件时出现问题

asp.net-mvc - 我无法将 Paypal 配置为在 ASP.NET MVC 应用程序中使用