0

I own this site: http://www.sohjel.ir ; I've implemented an option called: "Watch Bag", using ASP.NET Core 2.1 MVC Session. And my problem is: I want to return back to exactly where I click "Add To Watch Bag" in that page after I click this button and adding that lesson to "Watch Bag" instead of returning back to "Begin of Page". How do I do that?! Note that I've used this code in my Controller:

[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" });
}
jps
  • 20,041
  • 15
  • 75
  • 79
SohJel
  • 11
  • 6
  • You can use an anchor, see this question: https://stackoverflow.com/questions/602788/asp-net-mvc-redirecttoaction-with-anchor – mxmissile Mar 11 '19 at 15:09
  • Or.... https://stackoverflow.com/questions/484463/how-do-i-maintain-scroll-position-in-mvc (look at the not-accepted-answer) – Steve Mar 11 '19 at 15:11

1 Answers1

0

I solved my problem using first comment (By: mxmissile) in: Return back to exactly where i was in Page And first solution (By: mgebhard) in: https://forums.asp.net/p/2153690/6254332.aspx?return+back+to+exactly+where+I+click

So, In "Index" action method I used this code instead: return Redirect(Url.RouteUrl(new { controller = "Home", action = "Index" }) + "#" + id); And in its view I used this code: id="@lesson.Id" … And worked for me.

SohJel
  • 11
  • 6