我有兩個 URL,兩者都應解析為同一頁面。如果沒有,則返回 404http://localhost:xxx/Assets = 404 未找到http://localhost:xxx/Assets/Index = 按預期工作這是我的索引操作:[HttpGet]public IActionResult Index(){ var vm = new AssetsIndexModel() { /* snipped, not important */ }; return View(vm);}這是我在 Startup.cs 中的唯一路線:app.UseMvc(routes =>{ routes.MapRoute("default", "{Controller}/{Action}/{id?}", defaults: new { Controller = "Home", Action = "Index" });});這是解決此問題的唯一操作。同一控制器中的所有其他操作都能正確解析。另外,如果我只是沖浪到“/Home”,我的 Home/Index 路線就可以工作。我可以在那里省略“/Index”,但不能在我的資產控制器中省略。有誰知道我可能會忽略什么?編輯:此外,我使用以下代碼創建索引操作的鏈接<a asp-controller="Assets" asp-action="Index">Manage Assets</a>這會生成“/Assets”,因此 MVC 似乎知道它可以省略“Index”,但該鏈接不起作用并返回 404。
1 回答

翻閱古今
TA貢獻1780條經驗 獲得超5個贊
我在發現另一個問題(乍一看似乎無關)后找到了答案。
在我的 HomeController 中,添加了一個操作,如下所示:
[HttpGet("{assetId}")] public IActionResult AssetDetail(Guid assetId) { return View(); }
這就是問題所在。我想任何地方的任何行動都解決了這個行動。將上面的路線更改為此解決了它:
[HttpGet("Detail/{assetId}")]
- 1 回答
- 0 關注
- 101 瀏覽
添加回答
舉報
0/150
提交
取消