简体   繁体   中英

How to set a autoscroll from ASP.NET Core MVC #control

I am having an HTTP Post function in ASP.NET Core 5.0 MVC which is responsible for saving the values and redirect to index page with query string parameter ( ?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});

}

Upon submit I am getting URL in below format.

https://localhost:44324/ClubFederation?CID=5

But my requirement is in below format, is there any possibility from server side ASP.NET Core 5.0 MVC:

https://localhost:44324/ClubFederation?CID=5#controlid

Based on Hamed Naeemaei's answer , I would like to add that you need to add [HttpGet("Index")] to the page method you want to jump to.

Because after using return Redirect(Url.RouteUrl(new { controller = "ClubFederation", action = "Index", CID = 66}) + "#" + controlid); , we get the url like below.

https://xxx:port/ClubFederation/Index?CID=66#controlid

After add [HttpGet()], the url should be you want.


Test Code And Result

在此处输入图像描述

在此处输入图像描述

Try this:

return Redirect(Url.RouteUrl(new { controller = "ClubFederation", action = "Index", CID = 66}) + "#" + controlid);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM