Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC: The correct way to handle a cancel button

Tags:

asp.net-mvc

I'm wanting to have a simple cancel button so on confirmation of, say, the deletion of a product, they can change their mind and click cancel before the actual delete action is started.

I figure that on clicking the button you are wanting to redirect the user to the previous page. I understand that a common way to handle this is with javascript

onclick="javascript:history.back(1);"

Is this acceptable? If the user has javascript disabled, what happens then?

So instead, I figured that I would submit the form and an action would redirect the user to the previous page. Is this how it should be done? And if so, what is the C# code to do this?

Thanks for any help :)

like image 244
ajbeaven Avatar asked Oct 15 '22 13:10

ajbeaven


1 Answers

the only way you can do this without javascript is if you make a second form that POSTs to a different action (that will just redirect you) that just has a single submit button with cancel text.

If you are doing a web application, it is pretty much expected that javascript is a requirement. As far as I'm concerned, anyone who chooses to live without javascript nowadays is choosing to live with a broken internet, and it has been a very long time since browsers did not support it. The whole idea is just silly to me, sort of like the people who block cookies.

like image 110
Matt Briggs Avatar answered Oct 18 '22 12:10

Matt Briggs