返回到我点击的确切位置 [英] Return back to exactly where I click
本文介绍了返回到我点击的确切位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我拥有这个网站:http://www.sohjel.ir;我已经实现了一个名为Watch Bag的选项,使用ASP.NET Core 2.1 MVC Session。
我的问题是:我想回到我点击Add To Watch Bag的确切位置在我点击此按钮并将该课程添加到Watch Bag而不是返回Begin of Page之后的页面中。
我该怎么做?!
请注意,我在我的控制器中使用了这个代码:
我尝试了什么:
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" });
}
推荐答案
我使用第一条评论(由:mxmissile)解决了我的问题:
https://stackoverflow.com/questions/55104744/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
所以,在索引动作方法中我改为使用此代码:
返回重定向(Url.RouteUrl(new {controller =Home,action =Index}) +#+ id);
在其视图中我使用了以下代码:
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......
并为我工作。
并为我工作。
id="@lesson.Id" …
And worked for me.
And worked for me.
这篇关于返回到我点击的确切位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文