Thymeleaf:如何将按钮链接到另一个HTML页面?

6

我在我的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执行同样的任务,但是当我使用Thymeleaf时它不起作用。也就是说,当我点击按钮时没有任何反应。

2个回答

6

你好!

有很多方法可以实现,但我认为最简单的方法是给链接添加一个按钮类,就像下面的例子一样。由于这个类是bootstrap的类,所以你需要引用bootstrap。 由于你正在使用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"})
    }

2
将方法更改为“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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接