我有一个下拉菜单和一个操作链接。 当下拉列表更改时,将自动单击此操作链接。怎么做?。下面是我的代码,谢谢。
@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/