How do I add an anchor tag to my URL?

MVC 3.net I want to add a binding to the end of the URL.

I tried to include the anchor request line, but the hash '#' changes to% 23 or something similar in the url.

Is there any way around this?

+19
url tags asp.net-mvc-3 anchor add
Oct 26 2018-11-11T00:
source share
1 answer

There is an overload of the ActionLink helper , which allows you to specify a fragment:

@Html.ActionLink( "Link Text", // linkText "Action", // actionName "Controller", // controllerName null, // protocol null, // hostName "fragment", // fragment new { id = "123" }, // routeValues null // htmlAttributes ) 

will generate (when using default routes):

 <a href="/Controller/Action/123#fragment">Link Text</a> 



UPDATE:

and if you want to do this as part of the action of the controller performing the redirection, you can use the GenerateUrl method:

 public ActionResult Index() { var url = UrlHelper.GenerateUrl( null, "Action", "Controller", null, null, "fragment", new RouteValueDictionary(new { id = "123" }), Url.RouteCollection, Url.RequestContext, false ); return Redirect(url); } 
+36
Oct 26 2018-11-11T00:
source share



All Articles