If you use your own ActionLink extension line by line:
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, bool noEncode) { var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); var url = urlHelper.Action(actionName, controllerName, routeValues); if (noEncode) url = Uri.UnescapeDataString(url); var tagBuilder = new TagBuilder("a"); tagBuilder.MergeAttribute("href", url); tagBuilder.InnerHtml = linkText; return MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.Normal)); }
Then you can make your template as follows:
<p class="post-info"> <p class="post-info" data-bind="text UserName"></p> <span data-bind="Body"></span> <p class="post-footer"> @Html.ActionLink("Comments (${CommentCount})", "IndividualPost", "Post", new {id = "${id}"}, true) </p> </p>
the created server html will look like this:
<p class="post-info"> <p class="post-info" data-bind="text UserName"></p> <span data-bind="Body"></span> <p class="post-footer"> <a href="/Post/IndividualPost/${id}">Comments (${CommentCount})</a> </p> </p>
which, in turn, is the perfect template in my opinion.
The reason for the ActionLink extension is that the regular Html.ActionLink encodes your URL /Post/IndividualPost/%24%7Bid%7D , which does not work for the template
source share