Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to action from JavaScript method?

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(); } 
like image 338
r.r Avatar asked Mar 17 '11 08:03

r.r


People also ask

How do I redirect to another action?

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.

How do you redirect to another page in JavaScript with get data?

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.

How can you perform 301 redirects in JS?

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.

How to redirect a web page in JavaScript?

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.

What is redirecttoaction in MVC with example?

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.

What does the Redirect () Method of the response interface return?

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.

How do I redirect a response to a URL?

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.


1 Answers

To redirect:

function DeleteJob() {     if (confirm("Do you really want to delete selected job/s?"))         window.location.href = "your/url";     else         return false; } 
like image 94
Peter Porfy Avatar answered Sep 24 '22 03:09

Peter Porfy