【问题标题】:Return back to exactly where i was in Page返回到我在 Page 中的确切位置
【发布时间】:2026-01-12 23:25:02
【问题描述】:

我拥有这个网站:http://www.sohjel.ir;我使用 ASP.NET Core 2.1 MVC Session 实现了一个名为“Watch Bag”的选项。 我的问题是:单击此按钮并将该课程添加到“Watch Bag”而不是返回到“Begin of Page”后,我想返回到单击该页面中的“Add To Watch Bag”的确切位置。 我怎么做?! 请注意,我在控制器中使用了此代码:

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Index(int id)
{
    List<int> lstViewBag = HttpContext.Session.Get<List<int>>("sjViewBag");
    if (lstViewBag == null)
    {
        lstViewBag = new List<int>();
    }
    lstViewBag.Add(id);
    HttpContext.Session.Set("sjViewBag", lstViewBag);
    return RedirectToAction("Index", "Home", new { area = "Customer" });
}

【问题讨论】:

标签: asp.net-core asp.net-core-mvc


【解决方案1】:

我使用第一条评论(作者:mxmissile)解决了我的问题: Return back to exactly where i was in Page 第一个解决方案(作者:mgebhard)在: https://forums.asp.net/p/2153690/6254332.aspx?return+back+to+exactly+where+I+click

因此,在“索引”操作方法中,我使用了以下代码: return Redirect(Url.RouteUrl(new { controller = "Home", action = "Index" }) + "#" + id); 在它看来,我使用了这段代码: id="@lesson.Id" … 并为我工作。

【讨论】:

    最近更新 更多