Search code examples
jqueryasp.net-mvcasp.net-mvc-3jquery-templates

ASP.NET MVC ActionLink in jquery-tmpl template


I have a jquery-tmpl defined:

<script id="postTemplate" type="text/x-jquery-tmpl">
     <div class="div-msg-actions-inner">
          @Html.ActionLink("Edit", "Edit", "Post", new { postId = "${PostId}" }, new { @class = "button" })
          @Html.ActionLink("Reply", "Reply", "Post", new { topicId = "${TopicId}" }, new { @class = "button" })
     </div>
 </script>

The action link results in the "$" being encoded into "%24". Is there a way around this so the ID in my action link will get replaced correctly?


Solution

  • @Html.ActionLink("Edit", "Edit", "Post", new { postId = "999" }, new { @class = "post-button", })
    @Html.ActionLink("Reply", "Reply", "Post", new { topicId = "888" }, new { @class = "reply-button" })
    
    ...
    
    $("#postTemplate").text($("#postTemplate").text().replace("999", "${PostId}"));
    $("#postTemplate").text($("#postTemplate").text().replace("888", "${TopicId}"));
    

    This is the solution I ended up using.