Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

What I have tried:

[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" });
}
Posted
Updated 12-Mar-19 0:18am

1 solution

I solved my problem using first comment (By: mxmissile) in:
https://stackoverflow.com/questions/55104744/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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900