javascript - 如何在下拉列表更改时自动单击 ActionLink?
问题描述
我有一个下拉菜单和一个操作链接。当下拉列表更改时,将自动单击此操作链接。怎么做?。下面是我的代码,谢谢。
@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"})
控制器
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"})
您应该在下拉更改时调用 click 事件,如下所示:
<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。您必须注入 url 才能在 change 事件中传递 PaymentCode。
推荐阅读
- sql - Postgresql LEFT JOIN 返回比预期更多的结果
- javascript - Vue路由器beforeEach:陷入循环并且无法加载登录模板
- python - 替换方法替换相似字符我如何使它替换单个特定字符
- kubernetes - 日志文件在使用 Containerd 运行时的 K8s 集群中的什么位置?
- excel - 切割库存问题的工作流程是什么?
- typescript - Intellij IDEA 中的语言服务最大化 CPU
- ios - 在后台/终止状态下运行应用程序
- python - 调用 Python 脚本时在 .bat 文件脚本中动态传递文件名
- .net - 一次获取数据并在所有控制器中访问它?
- assembly - 程序集 x86,如何将二进制文件作为整数写入文件