java Thymeleaf:如何制作指向另一个 html 页面的按钮链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46216134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Thymeleaf: How to make a button link to another html page?
提问by sndu
I have an input button in my html page. I want to link the button to another html page with thymeleaf. This is my code.
我的 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>
My controller works fine. (I'm working with spring mvc). But I can't figure out what the problem is. I can do the same task using html. But when I am using thymeleaf its not working. That is when I clicked the button nothing happens.
我的控制器工作正常。(我正在使用 spring mvc)。但我无法弄清楚问题是什么。我可以使用 html 执行相同的任务。但是当我使用百里香叶时它不起作用。那是当我单击按钮时什么也没有发生。
采纳答案by Pashupati Khanal
Hi !
你好 !
There are many ways you can do but what I find the easiest is give a button class to a link as in following example. Since this class is a bootstrap's class so you need to have reference to bootstrap. Since you are using MVC it already got Bootstrap linked.
有很多方法可以做,但我发现最简单的方法是为链接提供一个按钮类,如下例所示。由于此类是引导程序的类,因此您需要引用引导程序。由于您使用的是 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> Back to List</a>
Next You can do following:
接下来您可以执行以下操作:
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
{
<input type="submit" value="Go To Dashboard" />
}
}
And in Index of Home You can do :
在首页索引中,您可以执行以下操作:
public ApplicationUserManager UserManager
{
return RedirectToAction("Index","Dashboard",new{area="Admin"})
}
回答by sndu
Adding the method as 'post' fixed the issue
将方法添加为“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>