sndu
sndu

Reputation: 1033

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

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.

Upvotes: 6

Views: 42587

Answers (2)

sndu
sndu

Reputation: 1033

Adding the method as 'post' fixed the issue

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

Upvotes: 2

Pashupati Khanal
Pashupati Khanal

Reputation: 743

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"})
    }

Upvotes: 6

Related Questions