在ASP.NET MVC中,重定向到调用页面可以通过以下几种方式实现:
RedirectToAction
方法:public ActionResult MyAction()
{
// 执行某些操作
return RedirectToAction("MyAction");
}
RedirectToRoute
方法:public ActionResult MyAction()
{
// 执行某些操作
return RedirectToRoute(new { controller = "MyController", action = "MyAction" });
}
Redirect
方法:public ActionResult MyAction()
{
// 执行某些操作
return Redirect("~/MyController/MyAction");
}
HttpContext.Response.Redirect
方法:public ActionResult MyAction()
{
// 执行某些操作
HttpContext.Response.Redirect("~/MyController/MyAction");
return new EmptyResult();
}
public ActionResult MyAction()
{
// 执行某些操作
return View("MyView", (object)new { redirectUrl = Url.Action("MyAction") });
}
在视图中,使用以下JavaScript代码实现重定向:
window.location.href = '@Model.redirectUrl';
</script>
这些方法都可以实现在ASP.NET MVC中重定向到调用页面。具体使用哪种方法取决于具体的需求和场景。
小程序云开发官方直播课(应用开发实战)
《民航智见》线上会议
TVP技术夜未眠
云+社区技术沙龙[第17期]
云+社区技术沙龙[第22期]
Hello Serverless 来了
腾讯技术开放日
云+社区技术沙龙[第1期]
领取专属 10元无门槛券
手把手带您无忧上云