首页 > 解决方案 > 如何覆盖表单中的 asp-action - Javascript

问题描述

我有一个这样的表单,我想使用 javascript 更改 asp-action,但下面的代码不会覆盖。我在这里做错了什么?

HTML

<form class="myform" id="myform" asp-action="Create" asp-controller="Users" method="get">
  <button type="submit">
</button>
</form>

JS

document.getElementById('myform').addEventListener('submit', (e) => {
    e.preventDefault();
    this.action = 'Index';
    this.submit();
});

标签: javascript

解决方案


我会尝试使用setAttribute,因为 asp-action 是 ASP 特定的参数。

this.setAttribute("asp-action","Index");

推荐阅读