【问题标题】:Thymeleaf: How to make a button link to another html page?Thymeleaf:如何使按钮链接到另一个 html 页面?
【发布时间】:2018-02-23 06:18:11
【问题描述】:

我的 html 页面中有一个输入按钮。我想用 thymeleaf 将按钮链接到另一个 html 页面。这是我的代码。

<form id="hotDealForm" th:action="@{/hot-deal-step-1}">
    <div class="col-xs-12 col-sm-6 col-md-6">
        This Hot deal
        <br/>
        <input type="button" value="Continue to schedule" class="btn btn-red"/>
    </div>
</form>

我的控制器工作正常。 (我正在使用spring mvc)。但我无法弄清楚问题是什么。我可以使用 html 完成相同的任务。但是当我使用百里香时它不起作用。那是当我点击按钮时没有任何反应。

【问题讨论】:

    标签: java html spring-mvc thymeleaf


    【解决方案1】:

    将方法添加为“post”解决了问题

    <form id = "hotDealForm" th:action = "@{/hot-deal-step-1}"  method="post">
    
        <div class="col-xs-12 col-sm-6 col-md-6">
            This Hot deal
            <br/>
        <input type="button" value="Continue to schedule" class="btn btn-red" />
        </div>
    
    </form>
    

    【讨论】:

      【解决方案2】:

      嗨!

      有很多方法可以做,但我发现最简单的方法是为链接提供一个按钮类,如下例所示。由于此类是引导程序的类,因此您需要参考引导程序。 由于您使用的是 MVC,因此它已经链接了 Bootstrap。

      <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
      <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
      
         
       <a href="@Url.Action("Index")" class="btn btn-success"> <i class="fa fa-arrow-circle-o-left"></i>&nbsp;Back to List</a>

      下一步您可以执行以下操作:

      @using (Html.BeginForm("Index", "Home", FormMethod.Post))
      

      {

      <input type="submit" value="Go To Dashboard" />
      

      }

      在首页索引中你可以这样做:

      public ApplicationUserManager UserManager
          {
            return RedirectToAction("Index","Dashboard",new{area="Admin"})
          }
      

      【讨论】:

        猜你喜欢
        • 2019-11-29
        • 2016-04-21
        • 2021-08-02
        • 2016-11-20
        • 2016-02-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多