Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cancel button in form

I have a cancel button in a form:

@using (Html.BeginForm("ConfirmBid","Auction"))
        {
          some stuff ...

                    <input type="image" src="../../Content/css/img/btn-submit.png" class="btn-form" />
                    <input type="image" src="../../Content/css/img/btn-cancel.png" class="btn-form" />

        }

The issue is I want this button to go to a particular view when I click on it. How do I do this?

like image 764
Sachin Kainth Avatar asked Mar 28 '12 18:03

Sachin Kainth


People also ask

What is the cancel button?

1. Cancel is a button or option that lets you exit a program or dialog box and not save any of the changes made.

What is Cancel button in HTML?

There is no button type="cancel" in html. You can try like this <a href="http://www.url.com/yourpage.php">Cancel</a> You can make it look like a button by using CSS style properties.

How do I clear a form with a button?

You can easily reset all form values using the HTML button using <input type=”reset”> attribute. Clicking the reset button restores the form to its original state (the default value) before the user started entering values into the fields, selecting radio buttons, checkboxes, etc.

How do I create a clear button in HTML?

Type the <input type="reset"> tag into the code towards the top and/or bottom of the HTML form. Close the form after all input fields are entered with a final </form> tag. Save and preview your new adjusted form with the new reset button.


2 Answers

Either you can convert the Cancel button as an anchor tag with @Html.ActionLink helper method and apply a css class which makes the link to looks like a button and then in the controller action for that link, you can return the specific view.

@Html.ActionLink("Cancel","Index","Products",null, new { @class="clsButtonFake"})

or

Use 2 submit buttons in the form. One for real submit and one for the cancel. and in your controller action, check which button called the action method. You can read more about it here in this answer.

like image 195
Shyju Avatar answered Oct 02 '22 08:10

Shyju


Lot of the answers worked in either of the browsers, chrome or ie but not all.

This worked in all -

<input type="button" value="Cancel" onclick="location.href='@Url.Action("Index","Home")';"/>
like image 27
zealoustechie Avatar answered Oct 02 '22 08:10

zealoustechie