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?

4

1 回答 1

1

您可以使用GenerateUrl静态方法:

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);
}

应该重定向到:

/currentController/List#abc
于 2012-04-14T06:53:03.880 回答