implement returnurl in asp.net mvc [closed]
How to implement returnurl in asp.net mvc?
Your question is very unclear so I can only be guessing. Personally I pass returnUrl
as parameter to actions that need to redirect:
[HttpPost]
public ActionResult Foo(string returnUrl)
{
// TODO: some processing ...
// TODO: sanitize the url ensuring that it belongs to the same domain
return Redirect(returnUrl);
}
and then I build HTML forms to invoke the action and pass the return url:
@using (Html.BeginForm())
{
@Html.Hidden("returnUrl", Url.Action("someaction", "somecontroller"))
<input type="submit" value="OK" />
}
We did something like this in one of our projects.
In your controller, add a parameter for the returnUrl then in your method just redirect to it.
public ActionResult SomeActionMethod(int id, string returnUrl)
{
//do some stuff
if (!string.IsNullOrWhiteSpace(returnUrl))
{
return Redirect(returnUrl);
}
else
{
//return whatever
}
}
精彩评论