简体   繁体   English

MVC3 Url.Action 查询字符串生成

[英]MVC3 Url.Action querystring generation

I am trying to generate an url for an MVC 3 action within javascript environment (in a cshtml file).我正在尝试为 javascript 环境(在 cshtml 文件中)中的 MVC 3 操作生成 url。

<script type="text/javascript">
  ...
  var src = "@Url.Action("GetProductImage", new { productId = Model.Product.Id, pos = 1, size = 0 })";
  $(document.createElement("img")).attr("src", src);
  ...
</script>

Now this works almost fine, my problem is that the querystring is being escaped.现在这几乎可以正常工作,我的问题是查询字符串正在被转义。 Instead of:代替:

"/Products/GetProductImage?productId=1&pos=0&size=0"

it generates:它生成:

"/Products/GetProductImage?productId=1&amp;pos=0&amp;size=0"

so my action does not get called.所以我的动作不会被调用。

Now I know I can make my own custom Url helper function, but I was wondering if I can use this or some other built in helper to get the unescaped URL?现在我知道我可以制作自己的自定义 Url 助手 function,但我想知道是否可以使用这个或其他一些内置助手来获得未转义的 ZE6B391A8D2C4D45902A23A8B6587?

Thanks in advance, G.在此先感谢,G。

<script type="text/javascript">
   var src = "@Html.Raw(Url.Action("GetProductImage", new { productId = Model.Product.Id, pos = 1, size = 0 }))";
   $(document.createElement("img")).attr("src", src);
</script>
var src = "@Html.Raw(Url.Action("GetProductImage", new { productId = Model.Product.Id, pos = 1, size = 0 }))";

Url.Action worked for me not HtmlUrl.Action Url.Action 对我有用,而不是HtmlUrl.Action

Enjoy!享受!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM