【发布时间】:2021-05-25 18:40:07
【问题描述】:
我需要一些帮助。
我正在使用 ASP.NET Core 3.1 MVC,一切顺利,但不是针对特定操作。
我有几个页面:开始 -> 索引 -> 添加用户。
感谢<button>s,我可以在我的页面之间导航。
Index.cshtml:
<form asp-controller="Home" asp-action="AddUser" asp-route-GB="@ViewBag.GB">
<button type="submit" class="btn btn-success">Add</button>
</form>
HomeController.cs:
[HttpGet]
public ActionResult Start(string GB) {
if (string.IsNullOrEmpty(GB)) {
return RedirectPermanent("Error");
}
else {
return View();
}
}
[HttpGet]
public ActionResult Index(string GB) {
if (string.IsNullOrEmpty(GB)) {
return RedirectPermanent("Error");
}
else {
return View();
}
}
[HttpGet]
public ActionResult AddUser(string GB) {
if (string.IsNullOrEmpty(GB)) {
return RedirectPermanent("Error");
}
else {
return View();
}
}
public ActionResult Error() {
return View();
}
网址结果:
https://localhost:XXXXX/Home/Start?GB=1 -> 进展顺利。
https://localhost:XXXXX/Home/Index?GB=1 -> 进展顺利。
https://localhost:XXXXX/Home/AddUser?GB=1 -> HTTP 错误 405
但是!如果我在最后一个斜杠上添加一个斜线:
https://localhost:XXXXX/Home/AddUser/?GB=1 -> 进展顺利。
发生了什么事?我不想在我的浏览器上添加斜线以使其正常工作...
【问题讨论】:
-
您能展示一下您的 AddUser 操作吗?
-
您有多个 AddUser* 路由吗?如果是这样,请尝试重命名路由名称并检查路由器无法正确识别此路由的原因。如果您还没有这样做,您可以通过添加路由属性 [HttpGet("AddUser?GB={gb})]" 使其更加明确。但是,根据提供的信息,无法回答为什么路线不是唯一匹配到操作的原因。
-
现在你得到了我的整个 HomeController.cs :)
标签: asp.net-mvc asp.net-core-mvc asp.net-core-3.1 http-status-code-405 slash