我在 ASP.NET Core 5.0 MVC 中有一個 HTTP Post 函式,它負責保存值并使用查詢字串引數重定向到索引頁 ( ?CID=66)
[HttpPost]
[ActionName("SaveClubPlayer")]
public async Task<IActionResult> SaveClubPlayer(ClubsPlayer aClubsPlayer)
{
if (ModelState.IsValid)
{
using (PortalDBContext aPortalDBContext = new PortalDBContext())
{
//Logic
await aPortalDBContext.SaveChangesAsync();
}
}
return RedirectToAction("Index", "ClubFederation", new { CID = 66});
}
提交后,我得到以下格式的 URL。
https://localhost:44324/ClubFederation?CID=5
但我的要求是以下格式,服務器端 ASP.NET Core 5.0 MVC 是否有可能:
https://localhost:44324/ClubFederation?CID=5#controlid
uj5u.com熱心網友回復:
試試這個:
return Redirect(Url.RouteUrl(new { controller = "ClubFederation", action = "Index", CID = 66}) "#" controlid);
uj5u.com熱心網友回復:
基于Hamed Naeemaei's answer,我想補充一點,您需要將 [HttpGet("Index")] 添加到您要跳轉到的頁面方法中。
因為使用之后return Redirect(Url.RouteUrl(new { controller = "ClubFederation", action = "Index", CID = 66}) "#" controlid);,我們得到了如下所示的網址。
https://xxx:port/ClubFederation/Index?CID=66#controlid
添加[HttpGet()]后,url應該是你想要的。
測驗代碼和結果


轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/391704.html
