Asp.net mvc 重定向到ASP.NET MVC3中的调用方操作

Asp.net mvc 重定向到ASP.NET MVC3中的调用方操作,asp.net-mvc,asp.net-mvc-3,action,redirecttoaction,Asp.net Mvc,Asp.net Mvc 3,Action,Redirecttoaction,假设我们有这样一个动作: public ActionResult Display(long Id){ //Do something return RedirectToAction(//To the Caller) } 因此,显示一些视图调用的动作,如: 索引视图:@Html.ActionLink(“显示”、“显示”,新的{Id=@Model.Id}) 所以我需要在中显示:返回重定向到操作(“索引”) 或 编辑视图:@Html.ActionLink(“显示”、“显示”,新建{Id=@M

假设我们有这样一个动作:

public ActionResult Display(long Id){

  //Do something

return RedirectToAction(//To the Caller)

}
因此,显示一些视图调用的动作,如:

索引视图
@Html.ActionLink(“显示”、“显示”,新的{Id=@Model.Id})

所以我需要在
中显示
返回重定向到操作(“索引”)

编辑视图
@Html.ActionLink(“显示”、“显示”,新建{Id=@Model.Id})

我需要在
中显示
返回重定向到操作(“编辑”)

等等


我们如何找到哪个动作调用
显示
,以及在返回给调用者动作的动作末尾?你有什么建议

在ActionLink方法中随id再传递一个参数怎么样

@Html.ActionLink("Show", "Display", new { Id=@Model.Id ,from="Edit"} )

在你的行动方法中,也要接受这一点

public ActionResult Display(long Id,string from)
{

  //Not 100 % sure what you want to do with the from variable value.
   return RedirectToAction(from);
}

在ActionLink方法中随id再传递一个参数怎么样

@Html.ActionLink("Show", "Display", new { Id=@Model.Id ,from="Edit"} )

在你的行动方法中,也要接受这一点

public ActionResult Display(long Id,string from)
{

  //Not 100 % sure what you want to do with the from variable value.
   return RedirectToAction(from);
}

如果不想将变量传递给重定向操作方法,还可以检查
Request.urlreferer
并使用它

public ActionResult Display(long Id){

    var caller = Request.UrlReferrer != null 
        ? Request.UrlReferrer : "DefaultRedirect";

    // do something

    return Redirect(caller);
}

如果不想将变量传递给重定向操作方法,还可以检查
Request.urlreferer
并使用它

public ActionResult Display(long Id){

    var caller = Request.UrlReferrer != null 
        ? Request.UrlReferrer : "DefaultRedirect";

    // do something

    return Redirect(caller);
}

您可以使用returnUrl参数

在调用方上:

@Html.ActionLink("Show", "Display", new { returnUrl = this.Url.PathAndQuery })
显示操作只需重定向到returnUrl:

this.Redirect(returnUrl);

这对于您将来可能遇到的任何其他情况都足够灵活。

您可以使用returnUrl参数

在调用方上:

@Html.ActionLink("Show", "Display", new { returnUrl = this.Url.PathAndQuery })
显示操作只需重定向到returnUrl:

this.Redirect(returnUrl);

这对于将来可能遇到的任何其他情况都足够灵活。

是否要在显示操作中执行重定向操作?的副本?是否要在显示操作中执行重定向操作?的副本?