I have an input type="button"
<input type="button" name="DeleteJob" runat="server" value="Löschen" onclick="DeleteJob()" />
and JavaScript method:
function DeleteJob() { if (confirm("Do you really want to delete selected job/s?")) return true; else return false; }
How can I instead return true, redirect to Action DeleteJob?
[HttpGet] public ActionResult DeleteJob(string selectedObject) { return View(); }
To redirect the user to another action method from the controller action method, we can use RedirectToAction method. Above action method will simply redirect the user to Create action method.
To redirect to another page in JavaScript, you can use window. location. href property, window. location will also work and if you want you can use window.
Are 301 redirects possible using JavaScript? Unfortunately not. That's not possible to do on the client-side. The 301 HTTP response code must be sent from the server, well before the JavaScript is executed by the browser.
There are several methods used for performing page redirection, but location.href and location.replace () are widely used. The page redirection is easy in JavaScript. window.location object is a property of the window object. There are several methods to redirect a web page.
RedirectToAction (String, Object) Redirects to the specified action using the action name and route values. C#. protected internal System.Web.Mvc.RedirectToRouteResult RedirectToAction (string actionName, object routeValues); member this.RedirectToAction : string * obj -> System.Web.Mvc.RedirectToRouteResult.
The redirect () method of the Response interface returns a Response resulting in a redirect to the specified URL. Note: This is mainly relevant to the ServiceWorker API. A controlling service worker could intercept a page's request and redirect it as desired.
Response.redirect () The redirect () method of the Response interface returns a Response resulting in a redirect to the specified URL. Note: This is mainly relevant to the ServiceWorker API. A controlling service worker could intercept a page's request and redirect it as desired.
To redirect:
function DeleteJob() { if (confirm("Do you really want to delete selected job/s?")) window.location.href = "your/url"; else return false; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With