1

I am trying to bypass the route value encoding that Html.ActionLink does, when processed on Server. For example I Have following ActionLink

@Html.ActionLink("Edit", "_SoftwareRequestEdit", "SoftwareRequest", new {id = "#= Id #"}, null)

and it generates a link like this

<a href="/Admin/SoftwareRequest/_SoftwareRequestEdit/%23%3d%20Id%20%23">Edit</a>

but I wan't to send this to the browser instead

<a href="/Admin/SoftwareRequest/_SoftwareRequestEdit/#= Id #">Edit</a>

The "#= Id #" route value has to be sent to the browser as it is, because it is processed by a front end framework Kendo UI Web, which replaces the expression "#= Id #" by a corresponding integer value.

0

2 Answers 2

1

This is quite messy... However, if you need to do it, you could always build the tag manually.

<a href="@(Url.Action("Edit", "_SoftwareRequestEdit", "SoftwareRequest"))/#= ID #">Edit</a>

Please note, I have not tested this code...

Edit: It may in fact give you what you need, because most browsers will url encode whatever is in the "a" tag anyway as spaces are not a valid url character: http://www.w3schools.com/tags/ref_urlencode.asp

Sign up to request clarification or add additional context in comments.

2 Comments

What if I wan't to use more than one route values (link parameters) ?
For this case, where I have to pass only one parameter, your solution works. So, I will close this question with your suggested answer.
0

Html.ActionLine has an overload with fragment param

public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes)

protocol and hostname can just pass empty string

3 Comments

I am sorry, but I don't understand your response. I tried using the overload that you suggested passing empty strings to host and protocol, but MVC still sends encoded link to the browser, as in my question.
routeValues={},fragment="= Id #"
I preferred the @FamiliarPie approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.