I have two ways of navigating to a form that I'm using. However, once this form has been submitted, I would like to return to the previous page that I was on. Is there a certain url path that I can navigate to based on which page I was on previously?
我有两种方式导航到我正在使用的表单。但是,一旦提交此表单,我想返回上一页。我可以根据之前在哪个页面导航到某个网址路径吗?
I'm using just a standard form and a mvc architecture.
我只使用标准表单和mvc架构。
Here's my controller for this form:
这是我的控制器:
[HttpPost]
public ActionResult Create(CreateConversationViewModel model)
{
try
{
_ConversationManager.Create(model.Message, model.GetReceivers(), model.SenderId);
return RedirectToAction("Me", "People");
}
catch (ValidationException ex)
{
ex.AddToModelState(ViewData.ModelState);
}
return View(model);
}
when I return to the People/Me page, that would only redirect to one of the pages.
当我返回People / Me页面时,它只会重定向到其中一个页面。
1 个解决方案
#1
1
You can use Request.UrlReferrer Property. Be aware that in can be spoofed quite easily. The best way to do this is to store the previous page on the current user's session, or you can hide the previous URL in the ViewModel as explanied here.
您可以使用Request.UrlReferrer属性。请注意,可以很容易地欺骗。执行此操作的最佳方法是将上一页存储在当前用户的会话中,或者您可以在ViewModel中隐藏先前的URL,如此处所述。
I hope this helps, good luck!
我希望这有帮助,祝你好运!
#1
1
You can use Request.UrlReferrer Property. Be aware that in can be spoofed quite easily. The best way to do this is to store the previous page on the current user's session, or you can hide the previous URL in the ViewModel as explanied here.
您可以使用Request.UrlReferrer属性。请注意,可以很容易地欺骗。执行此操作的最佳方法是将上一页存储在当前用户的会话中,或者您可以在ViewModel中隐藏先前的URL,如此处所述。
I hope this helps, good luck!
我希望这有帮助,祝你好运!