I have a web application in ASP.NET MVC and in there i have a jqueryUI tab with forms in. And when i submit i want to return to the open tab.
With me RedirectToAction() i create the url
www.foo.com/CV/edit/9
But i want to be able to generate
www.foo.com/CV/edit/9#tab-2
I tried with RedirectToAction("edit/"+id+"#tab-2"), but that generates:
www.foo.com/CV/edit/9%23tab-2
any1 knows the answer?
The RedirectToAction() method makes new requests and URL in the browser's address bar is updated with the generated URL by MVC. Between RedirectToAction() and Redirect() methods, best practice is to use RedirectToAction() for anything dealing with your application actions/controllers.
RedirectToAction is meant for doing 302 redirects within your application and gives you an easier way to work with your route table. Redirect is meant for doing 302 redirects to everything else, specifically external URLs, but you can still redirect within your application, you just have to construct the URLs yourself.
Second, to pass multiple parameters that the controller method expects, create a new instance of RouteValueDictionary and set the name/value pairs to pass to the method. Finally call RedirectToAction(), specifying the method name, controller name, and route values dictionary.
RedirectToRoute(String, Object)Redirects to the specified route using the route name and route values.
Create the URL, then append #tab-2
to it. Return a RedirectResult to redirect to the created URL:
return new RedirectResult(Url.Action("edit", new { id }) + "#tab-2");
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