Вопрос

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.

Это было полезно?

Решение

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

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top