例如,我有一些带有操作链接的 View :
@Html.ActionLink("Action", "Controller")
Action
操作返回一些 View :
public ActionResult Action()
{
string someModelForView = "some url i need to redirect after view was fully loaded";
return View("SomeView", someModelForView);
}
我需要的是在 View 完全加载后将用户重定向到在 someModelForView
模型中定义的 url,并且执行该页面上的所有 JavaScript。这个 View 可能是空的,没有任何内容,我只需要执行一些javascript,然后将用户重定向到外部页面。如何才能做到这一点?
最佳答案
渲染 View 并加载 JavaScript 后,您(服务器)就已经将响应(封装在返回的 ActionResult
中)发送到客户端(浏览器)。因此,您不能让 ASP.NET MVC 重定向您 – 服务器已完成对请求的处理。
不过,您可以使用 JavaScript 重定向:
// Here goes your JavaScript code that needs to be executed
// ...
// ... and here comes the redirect:
window.location.href = "http://newurl.com";
关于c# - ASP .NET MVC 加载后如何将用户从 View 重定向到另一个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13312324/