【发布时间】:2020-02-20 13:06:00
【问题描述】:
我正在从我开始学习的 asp.net 核心中得到这种意外行为。
我的视图中有以下表格:
<form asp-controller="Account" asp-action="Login" method="post">
<button type="submit">LOGIN</button>
</form>
是的,我在这里使用标签助手。这是控制器:
public class AccountController : Controller
{
[HttpPost]
[AllowAnonymous]
public async Task<IActionResult> Login(string returnUrl)
{
if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
return RedirectToAction("index", "home");
else
return LocalRedirect(returnUrl);
}
}
现在根据我目前的理解,returnUrl 应该自动获取查询字符串值,如果它存在于查询字符串中。但是有了这个设置,它就不会发生。经过一番摸索后,我在网上找到了一个解决方案,将我的观点改为:
<form method="post">
<button type="submit">LOGIN</button>
</form>
然后它开始工作。但是为什么会有这种行为,是什么原因造成的,为什么表单标签助手不让查询字符串绑定到这个 post 方法表单???
【问题讨论】:
标签: c# asp.net-mvc asp.net-core asp.net-core-tag-helpers