我们正在更新MVC应用程序。目前,我们无法更改任何后端代码,需要在剃刀页面上进行内联重定向。如何直接在剃刀页面中重定向到URL?
答案 0 :(得分:4)
一种可能性是使用Redirect
方法:
@{
Response.Redirect("http://google.com");
}
或者如果您想在同一个应用程序中重定向到控制器操作:
@{
Response.Redirect(Url.Action("SomeAction", "SomeController"));
}
这将通过返回302状态代码在服务器上执行重定向。如果要在客户端上进行重定向,可以使用DOM头部的元标记:
<meta http-equiv="refresh" content="0;URL=http://google.com">
或普通javascript:
<script>
window.location = 'http://google.com';
</script>