使用存储在剃刀Url.Content图像路径的变量 [英] Use a variable that store image path in Razor Url.Content

查看:412
本文介绍了使用存储在剃刀Url.Content图像路径的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个函数来动态构造的图像路径​​是这样的:

I used a function to construct an image path dynamically like this:

  function () {
            var name = $(this).attr('id') + '_o';
            var newsrc = '../../Content/HomePage/' + name + '.png';

我要分配使用剃刀 Url.Content 以图像标记作为其源的newsrc。所以,我希望做这样的事情:

And I want to assign the newsrc using Razor Url.Content to an image tag as its source. SO, I wish to do something like this:

  $(this).attr('src', '@Url.Content(newsrc)');

不过VS告诉我的红线说,newsrc不是当前环境中存在的..
我如何使用一个变量,Url.Content一起?

But VS show me red line saying that the newsrc is not exist within current context.. How can I use a variable along with Url.Content?

(注:我用这里面的脚本标记......)

(Note: I am using this inside script tag...)

编辑:一个想法在我脑海中,或许借壳将被传递到newsrc控制器,使用Url.Content那里解析URL,并将其传递回?是否可行?

An idea comes to my mind, perhaps the backdoor will be passing the newsrc to controller, use Url.Content there to resolve the url and pass it back? Is it feasible?

任何帮助将AP preciated ..

Any help will be appreciated..

推荐答案

问题由我的高级解决。我创建在web.config中(一WebDirectory)额外的AppSettings然后分配的值作为文件夹路径。

Problem solved by my senior. I create an extra appsettings in web.config ( a WebDirectory) then assign the value as the folder path.

然后,在我的code,我可以轻松地使用构造我的网址:

Then, at my code, I can easily construct my url using:

 System.Configuration.ConfigurationManager.AppSettings["WebDirectory"].ToString()...

这里只是分享我的解决方案,希望这将有助于有人在未来。谢谢你。

Just share my solution here, hope it will help someone in future. Thanks.

这篇关于使用存储在剃刀Url.Content图像路径的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆