首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何重定向到ASP.NET MVC中的调用页面?

在ASP.NET MVC中,重定向到调用页面可以通过以下几种方式实现:

  1. 使用RedirectToAction方法:
代码语言:csharp
复制
public ActionResult MyAction()
{
    // 执行某些操作
    return RedirectToAction("MyAction");
}
  1. 使用RedirectToRoute方法:
代码语言:csharp
复制
public ActionResult MyAction()
{
    // 执行某些操作
    return RedirectToRoute(new { controller = "MyController", action = "MyAction" });
}
  1. 使用Redirect方法:
代码语言:csharp
复制
public ActionResult MyAction()
{
    // 执行某些操作
    return Redirect("~/MyController/MyAction");
}
  1. 使用HttpContext.Response.Redirect方法:
代码语言:csharp
复制
public ActionResult MyAction()
{
    // 执行某些操作
    HttpContext.Response.Redirect("~/MyController/MyAction");
    return new EmptyResult();
}
  1. 使用JavaScript代码实现:
代码语言:csharp
复制
public ActionResult MyAction()
{
    // 执行某些操作
    return View("MyView", (object)new { redirectUrl = Url.Action("MyAction") });
}

在视图中,使用以下JavaScript代码实现重定向:

代码语言:html<script>
复制
    window.location.href = '@Model.redirectUrl';
</script>

这些方法都可以实现在ASP.NET MVC中重定向到调用页面。具体使用哪种方法取决于具体的需求和场景。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券