Asp.net mvc 在asp.net mvc中实现returnurl

Asp.net mvc 在asp.net mvc中实现returnurl,asp.net-mvc,Asp.net Mvc,如何在asp.net mvc中实现returnurl?您的问题很不清楚,所以我只能猜测。我个人将returnUrl作为参数传递给需要重定向的操作: [HttpPost] public ActionResult Foo(string returnUrl) { // TODO: some processing ... // TODO: sanitize the url ensuring that it belongs to the same domain return Re

如何在asp.net mvc中实现returnurl?

您的问题很不清楚,所以我只能猜测。我个人将
returnUrl
作为参数传递给需要重定向的操作:

[HttpPost]
public ActionResult Foo(string returnUrl)
{
    // TODO: some processing ...

    // TODO: sanitize the url ensuring that it belongs to the same domain
    return Redirect(returnUrl);
}
然后我构建HTML表单来调用操作并传递返回url:

@using (Html.BeginForm())
{
    @Html.Hidden("returnUrl", Url.Action("someaction", "somecontroller"))
    <input type="submit" value="OK" />
}
@使用(Html.BeginForm())
{
@Hidden(“returnUrl”,Url.Action(“someaction”,“somecontroller”))
}

我们在一个项目中做了类似的事情

在控制器中,为returnUrl添加一个参数,然后在方法中重定向到它

public ActionResult SomeActionMethod(int id, string returnUrl)
{
    //do some stuff

    if (!string.IsNullOrWhiteSpace(returnUrl))
    {
        return Redirect(returnUrl);
    }
    else
    {
        //return whatever
    }
}