2

I tried using

return RedirectToAction("List#"+Name.Substring(0,1));

but I get a 404 error and the address bar suggest that I am looking for List%23A.

EDIT "List" is the action name, and I would like to redirect directly to the First Letter anchor.

How do I pass the number sign?

MrM
  • 21,709
  • 30
  • 113
  • 139

1 Answers1

1

You could use the GenerateUrl static method:

public ActionResult Foo()
{
    string url = UrlHelper.GenerateUrl(
        null,                     // routeName
        "List",                   // actionName
        null,                     // controllerName
        null,                     // protocol
        null,                     // hostName
        "abc",                    // fragment <- that's what you are interested in
        null,                     // routeValues
        RouteTable.Routes,        // routeCollection
        Request.RequestContext,   // requestContext
        true                      // includeImplicitMvcValues
    );
    return Redirect(url);
}

should redirect to:

/currentController/List#abc
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928