How do I redirect a user when a button is clicked?

前端 未结 10 759
情话喂你
情话喂你 2020-12-13 05:30

I have a view with a button. When the user clicks the button I want them redirected to a data entry view. How do I accomplish this? I should mention the views are created, t

相关标签:
10条回答
  • 2020-12-13 06:32

    Or, if none of the above works then you can use following approach as it worked for me.

    Imagine this is your button

    <button class="btn" onclick="NavigateToPdf(${Id});"></button>
    

    I got the value for ${Id} filled using jquery templates. You can use whatever suits your requirement. In the following function, I am setting window.location.href equal to controller name then action name and then finally parameter. I am able to successfully navigate.

    function NavigateToPdf(id) {
        window.location.href = "Link/Pdf/" + id;
    }
    

    I hope it helps.

    0 讨论(0)
  • 2020-12-13 06:32

    You can easily wrap your button tag with tag.Using Url.Action() HTML Helper this will get to navigate to one page to another.

    <a href='@Url.Action("YourAction", "YourController")'>
        <input type='button' value='Dummy Button' />
    </a>
    

    If you want to navigate with javascript onclick() function then use

    <input type='button' value='Dummy Button' onclick='window.location = "@Url.Action("YourAction", "YourController")";' />
    
    0 讨论(0)
  • 2020-12-13 06:33

    if using JQuery, you can do this :

    <script type="text/javascript">
        $('#buttonid').click(function () {
            document.location = '@Url.Action("ActionName","ControllerName")';
        });
    </script>
    
    0 讨论(0)
  • 2020-12-13 06:34
    <li class="nav-item">
        <a class="nav-link text-dark" asp-area="" asp-page="/UsersPage">Users</a>
    </li>
    

    Try this

    0 讨论(0)
提交回复
热议问题