MVC3 Url.Action查询字符串代 [英] MVC3 Url.Action querystring generation
本文介绍了MVC3 Url.Action查询字符串代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想生成JavaScript环境内的MVC 3操作的URL(在CSHTML文件)。
<脚本类型=文/ JavaScript的>
...
变种SRC =@ Url.Action(GetProductImage,新{=的productId Model.Product.Id,POS = 1,大小= 0});
$(使用document.createElement(img目录))ATTR(src用户,SRC)。
...
< / SCRIPT>
现在这个作品几乎罚款,我的问题是,查询字符串被转义。
相反的:
/产品/ GetProductImage的productId = 1&放大器; POS = 0&安培;大小= 0
它生成:
/产品/ GetProductImage的productId = 1&放大器;放大器; POS = 0&放大器;放大器;大小= 0
所以我的行动不会被调用。
现在我知道我可以让我的自定义的URL辅助函数,但我不知道我是否可以使用这个或其它一些内置的帮助,以获得转义网址是什么?
在此先感谢,G。
解决方案
<脚本类型=文/ JavaScript的>
变种SRC =@ Html.Raw(Url.Action(GetProductImage,新{=的productId Model.Product.Id,POS = 1,大小= 0}));
$(使用document.createElement(img目录))ATTR(src用户,SRC)。
< / SCRIPT>
I am trying to generate an url for an MVC 3 action within javascript environment (in a cshtml file).
<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&pos=0&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?
Thanks in advance, 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>
这篇关于MVC3 Url.Action查询字符串代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文