Search code examples
asp.net-mvcencodingjquery-templatesurlhelper

Mvc UrlHelper in conjunction with JQuery Templates


I would like to use the Mvc UrlHelper in conjunction with JQuery Templates.

Example template...

...
{{each Items}}        
    <div>
        <%= Url.Action("Action", "Controller", new { Id = "${$value.Id}" })%>
    </div> 
{{/each}}
...

The Url helper Action method encodes the template placeholder that I pass in as the Id parameter. This renders as..

...
<div>
    /web/controller/%24%7B%24value.Id%7D/action
</div>
<div>
    /web/controller/%24%7B%24value.Id%7D/action
</div>
...

I could really do with a way to prevent the Action method from encoding the Id parameter value, but I suppose it’s only doing its job!


Solution

  • unfortunately its by design and you'll have to work around it - see Rick Strahl's post on this

    http://west-wind.com/weblog/posts/831885.aspx