Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf: How to make a button link to another html page?

Tags:

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.

<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.

like image 219
sndu Avatar asked Sep 14 '17 10:09

sndu


People also ask

How do you pass parameters in Thymeleaf?

Request parameters can be easily accessed in Thymeleaf views. Request parameters are passed from the client to server like: https://example.com/query?q=Thymeleaf+Is+Great! In the above example if parameter q is not present, empty string will be displayed in the above paragraph otherwise the value of q will be shown.

How do you use Thymeleaf fragments?

There are three basic ways to include content from a fragment: insert – inserts content inside the tag. replace – replaces the current tag with the tag defining the fragment. include – this is deprecated but it may still appear in a legacy code.


1 Answers

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.

<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>

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"})
    }
like image 179
Pashupati Khanal Avatar answered Sep 30 '22 00:09

Pashupati Khanal