找不到 ASP 核心路由开机自检页面



我有标准的asp核心路由设置:

endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();

然后我有4个行动(2得到和2张贴(:

public async Task<IActionResult> Edit(int? id)
{...}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, CustomDTO customDTO)
{...}
public async Task<IActionResult> Review(int? id)
{...}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Review(int id, DifferentCustomDTO differentCustomDTO)
{...}

评论表单剃刀的开头是这样的:

<form asp-action="Review">

两个url看起来都是这样的:

https://localhost/MyController/Review/12

在正常情况下,POST操作将从url值获取其id,并从表单提交的数据获取CustomDTO。这一直有效,直到最近我开始得到这个:

This localhost page can’t be found No webpage was found for the web address: 
https://localhost/MyController/Review/12
HTTP ERROR 404

我试着去掉4个中的2个,看看是否存在某种冲突,但这并没有改变任何事情。我怎么能找到我搞砸的东西?

您需要在帖子正文中添加一些数据,因为如果您使用的是以下URL:

https://localhost/MyController/Review/12

然后,发布请求的HTML正文将为空。尝试将隐藏字段添加到表单中,如:

@Html.HiddenFor(e => e.Id)

最新更新