Cancel button in form

Sachin Kainth picture Sachin Kainth · Mar 28, 2012 · Viewed 38.2k times · Source

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?

Answer

Shyju picture Shyju · Mar 28, 2012

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.