Hello I want to return an anchor from Mvc Controller
Controller name= DefaultController;
public ActionResult MyAction(int id) { return RedirectToAction("Index", "region") }
So that the url when directed to index is
http://localhost/Default/#region
So that
<a href=#region>the content should be focus here</a>
I am not asking if you can do it like this: How can I add an anchor tag to my URL?
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.
By including a NuGet package called MvcContrib you can easily pass model or form data through a simple RedirectToAction function call inside of your controllers. The data will then be handled in the other view and be strongly typed to the model you are passing through the redirect.
I found this way:
public ActionResult MyAction(int id) { return new RedirectResult(Url.Action("Index") + "#region"); }
You can also use this verbose way:
var url = UrlHelper.GenerateUrl( null, "Index", "DefaultController", null, null, "region", null, null, Url.RequestContext, false ); return Redirect(url);
http://msdn.microsoft.com/en-us/library/ee703653.aspx
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