Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RedirectToAction() with tab-id

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?

like image 376
Frederiek Avatar asked Oct 11 '11 11:10

Frederiek


People also ask

How to use RedirectToAction in MVC?

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.

What is difference between Redirect and RedirectToAction?

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.

How pass multiple parameters in RedirectToAction in MVC?

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.

What is Redirect to route in MVC?

RedirectToRoute(String, Object)Redirects to the specified route using the route name and route values.


1 Answers

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");
like image 128
Sjoerd Avatar answered Sep 28 '22 01:09

Sjoerd