jquery-tmpl 模板中的 ASP.NET MVC ActionLink
我定义了一个jquery-tmpl:
<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>
操作链接导致“$”被编码为“%24”。有没有办法解决这个问题,以便正确替换我的操作链接中的 ID?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
继续发送相同的路由值参数,但将此脚本放在布局的末尾。它将替换每个页面中所有模板中的所有 ${propName} 字符串。
Continue sending route value parameter the same, but Put this script in the end of your layout. it will replace all the ${propName} strings back in all templates in every page.
这是我最终使用的解决方案。
This is the solution I ended up using.
实现此目的的一种方法是跳过 ActionLink Helper 并使用简单的 HTML 锚标记,例如,
我知道这并不理想,但这对我有用。
One way you could achieve this is to skip the ActionLink Helper and use a simple HTML anchor tag e.g.
Not ideal I know but this worked for me.
将
Html.Raw
与Url.Action
结合使用您是否尝试过将
Html.Raw
与Url.Action
结合使用?因此,您不必使用Html.ActionLink
创建链接,而是生成常规 HTML,并且不对特定链接/锚点的 URL 进行编码。这应该将模板变量保留在模板内。
将
Html.Raw
与Html.ActionLink
结合使用我想您已经尝试过:
Using
Html.Raw
withUrl.Action
Have you tried using
Html.Raw
in combination withUrl.Action
? So instead of creating links withHtml.ActionLink
you rather generate regular HTML and don't encode URL of that particular link/anchor.This should keep the template variable inside your template.
Using
Html.Raw
withHtml.ActionLink
I suppose you've tried this: