无法将提交重定向到操作

Can't redirect the submit to an action

我有以下操作并查看以下 the docs

[HttpPost("validate")]
public IActionResult Validate([FromQuery] string user, string pass)
{ ... }

[HttpGet("login")]
public IActionResult LogIn([FromQuery] string returnUrl)
{ 
  ...
  return View(model); 
}
@using Microsoft.AspNetCore.Mvc.TagHelpers;
@model Dictionary<string, string>

<form asp-controller="account" asp-action="validate" method="post">
  <input asp-for="@Model["user"]" placeholder="Username" />
  <input asp-for="@Model["pass"]" placeholder="Password" />
  <button type="submit">Go!</button>
</form>

单击按钮后,我返回到指定的相同操作(即 LogIn)insteda(即 Validate) .似乎我在表单中唯一控制的就是方法。我添加了 using 语句来访问 但它似乎没有什么区别。

我能错过什么?

The final rendition (ctrl+u in Chrome or F12 and check for the elements) produces <form asp-controller="account" asp-action="validate" method="post">...<button type="submit">Check the credentials</button> </form>. I was expecting the asp-xxx attributes to be transformed. Was I mistaken?

不,你是对的。这些标签助手属性应该已经转换为单个 action 属性,其中包含 URL 到您的 Validate 操作的目标。

由于属性没有被转换,这意味着标签助手没有 运行。这很可能是由于缺少 @addTagHelper 指令造成的。

您需要在视图本身或 _ViewImports.cshtml 文件中(默认情况下该行所在的位置)包含以下行:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

不需要使用 @using 指令导入命名空间。