Redirect to a hash from the controller using "RedirectToAction"

asp.net-mvc, asp.net-mvc-3, asp.net-mvc-4

Solution

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

Problem

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?

Original source

Related problems