【问题标题】:Button type ="submit" also redirects to another page after submitting?按钮类型="submit" 提交后也重定向到另一个页面?
【发布时间】:2018-12-22 10:22:22
【问题描述】:

我怎样才能让我的按钮“”input type="submit" value="Create" class="btn btn-default" 提交后也重定向到另一个页面(视图)?基本上,我制作了一个简单的表单,在单击该按钮后发送电子邮件,并自动将我返回到索引页面(默认控制器选项(asp.net mvc core)),我想将其重定向到另一个“感谢您提交电子邮件”页面(查看)。

【问题讨论】:

  • 标签使用不正确。请不要使用对问题没有意义的标签。即 [css] 标签

标签: html redirect button asp.net-core


【解决方案1】:

在表单元素中使用 action 属性,将您重定向到您想要的页面,

只需要提供该文件或页面的链接或目录,或者如果您已创建路由,则根据您使用的框架提供路由路径 this will help you for clear understanding

<form action="another_page.php"> <input type="text"> <button type="submit"> </form>

【讨论】:

    【解决方案2】:

    //在PHP中你可以使用

    redirect('thank-you.php'); 
    or 
    header('location:thank-you.php');
    

    /* 一段时间后重定向索引或主页的函数,您可以在感谢页面中编写 setTimeout 函数。*/

    <script>
      $(function(){
       setTimeout(function(){ window.location.href = "index.php"; }, 3000);
    });
    </script>
    

    // 我希望这对你有用。

    【讨论】:

    • 别忘了为 cmets 添加 //
    • 当然,我会进一步考虑@lorddirt
    【解决方案3】:

    您忘记在表单标签中添加action='index.php'

    例如

    <form action='index.php'>
    <input type='submit'/>
    </form>

    给出404错误,因为没有index.php这样的页面

    【讨论】:

      【解决方案4】:

      你可以使用 return RedirectToPage("谢谢");
      作为控制器 Action 的返回语句,以便它重定向到Thankyou.cshtml 页面。

      【讨论】:

      • 返回视图("NameOfView");也可以在接受表单数据的 post 方法中使用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 2013-06-14
      相关资源
      最近更新 更多