开发者

How can I add custom URL parameters to a MVC RedirectToAction

开发者 https://www.devze.com 2022-12-20 00:25 出处:网络
I currently have a simple MVC RedirectToAction action: return RedirectToAction(\"Edit\", \"Customers\", new {Id = iNewId});

I currently have a simple MVC RedirectToAction action:

return RedirectToAction("Edit", "Customers", new {Id = iNewId});

which redirects to Cutomers/Edit/1

However I'd like to append some custom values to the URL which will get used by javascript, returning URLs such as Cutomers/Edit/1#Tab1

What is the best开发者_C百科 method of doing this?


routes.MapRoute("WithTarget", "{controller}/{action}/{id}#{target}");

and

RedirectToAction("Edit", "Customers", new { id = iNewId, target = "Tab1" });

or

RedirectToRoute("WithTarget", new { controller = "Customers", action = "Edit", id = iNewId, target = "Tab1" });

But remember that the fragment is never sent from the client to the web server, so there's no way to read its value in a controller action.

0

精彩评论

暂无评论...
验证码 换一张
取 消