[英]How do I redirect to another page in my application using mvc
I am using Web API MVC SPA application and I would like to know how to redirect to another page using javascript. 我正在使用Web API MVC SPA应用程序,我想知道如何使用javascript重定向到另一个页面。 I have pasted my code below but it is not working 我在下面粘贴了我的代码,但是它不起作用
This is the code I have at the bottom of my cshtml page 这是我在cshtml页面底部的代码
<input type="button" onclick="redirectToUploadPage()" value="Login" />
@Html.Hidden("RedirectTo", Url.Action("_test", "Home"));
<script>
function redirectToUploadPage() {
var url = $("#RedirectTo").val();
}
</script>
My route config
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "test",
// url: "",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "test", id = UrlParameter.Optional });
My controller
public ActionResult test()
{
return PartialView("test");
}
In my browser it shows that it is trying to redirect to the test page because in my browser it shows http://localhost:55851/#!test.cshtml
but it does not redirect to that page 在我的浏览器中,它表明它正在尝试重定向到测试页面,因为在我的浏览器中,它显示了http://localhost:55851/#!test.cshtml
但它没有重定向到该页面
<input type="button" onclick="redirectToUploadPage()" value="Login" />
<script> function redirectToUploadPage() { location.replace("#!test.cshtml") } </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.