简体   繁体   English

如何使用mvc重定向到应用程序中的另一个页面

[英]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.

相关问题 检查电子邮件输入验证后,如何使用我的按钮将用户重定向到另一个HTML页面? - How do I redirect the user to another HTML page using my button after checking for email input validation? 单击应用程序通知后,如何重定向到我的应用程序配置文件页面? - How do I redirect to my application profile page after I click on the application notification? 如何使用addEventListener使按钮将页面重定向到另一个页面? - How can I make a button redirect my page to another page using addEventListener? 如何在MVC页面中使用JavaScript重定向到另一个网址 - How To Redirect To Another Url Using JavaScript In MVC Page 更改 redux 商店 state 后,如何重定向到我的反应应用程序中的另一个页面? - How do I redirect to another page in my react app after changing the redux store state? 我希望我的 html 页面在我提交某个输入时重定向到另一个 html 页面我该怎么做 - I want my html page to redirect to another html page when I submit a certain input how can i do that 如何允许将丢失的下拉列表项添加到数据库而又不将页面留在我的MVC应用程序中? - How do I allow missing dropdown list items to be added to a database without leaving the page in my MVC application? 如何使用 Z686155AF75A60A0EDD3F6E9D80C1 从 ASP.NET Controller 重定向到另一个 web 页面? - How do I redirect to another web page from an ASP.NET Controller using JavaScript? 托管我的网站后如何使用 php 重定向到另一个页面 - how to redirect to another page using php after hosting my website 如何使用控制器动作使按钮将页面重定向到另一个页面,并使用javascript传递值? - How can I make a button redirect my page to another page using a controller action and passing a value using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM