嵌入一​​个spark变量来组成一个字符串

发布于 2024-09-26 11:29:57 字数 423 浏览 0 评论 0原文

你好,spark 新手,所以这应该很简单。

我正在使用 Spark 将旧的 webfoms 页面转换为 mvc。 我想使用 Base.Application 来组成 url

原始标记

<img alt="" src="<%= Base.ApplicationPath %>images/screenshots/myImage.jpg" />

的 src我已经在 Spark 中尝试过了,

<img alt= src=${  Base.ApplicationPath }+">images/screenshots/myImage.jpg" />

但没有任何乐趣。

我如何在火花中做到这一点?

Hi new to spark so this should be simple.

I'm converting an old webfoms page to mvc using spark.
I want to use the Base.Application to make up the src of a url

original markup

<img alt="" src="<%= Base.ApplicationPath %>images/screenshots/myImage.jpg" />

I've tried this in spark

<img alt= src=${  Base.ApplicationPath }+">images/screenshots/myImage.jpg" />

but no joy.

How do i do this in spark?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泡沫很甜 2024-10-03 11:29:57

不确定您是否意识到这一点,但 Spark 有一个 DefaultResourcePathManager,如果您在资源中添加波浪号前缀,它会自动定位站点根目录,因此这应该可以正常工作,并且看起来更整洁。

<img alt="" src="~/images/screenshots/myImage.jpg" />

使用这种技术还有一个额外的好处......抓住你的短裤!在不改变您的视图的情况下,只需确保使用波形符约定,您就可以动态地将静态资源的请求重定向到内容分发网络 (CDN) 或完全不同的位置 - 甚至是您编译的 Spark Module .dll 内的嵌入式资源用于部署中的 dll 删除。

例如,要将其连接到 CDN,您所需要做的就是将以下类型的内容添加到您的 Spark 设置中:

<resources>
  <add match="/content/images" location="http://mycdn.com/youraccount/images"/>
  <add match="/content/css" location="http://mycdn.com/youraccount/css"/>
  <add match="/content/js" location="http://mycdn.com/youraccount/js"/>
</resources>

...从那时起,这些资源将从新位置获取。这对于本地场景测试以及稍后部署到云非常有用。

Not sure if you're aware of this, but Spark has a DefaultResourcePathManager that will automatically locate the Site Root if you prefix the resource with a tilde, so this should work just fine, and looks neater.

<img alt="" src="~/images/screenshots/myImage.jpg" />

There's an added bonus to using this technique as well....hold on to your shorts! Without changing your view, simply by making sure you use the tilde convention, you can dynamically redirect requests for your static resources to a content delivery network (CDN) or a completely different location - even an embedded resource inside a Spark Module .dll you compile for dll drop in deployment.

For example, to hook it up to a CDN, all you'll need to do is add the following kind of thing to your Spark Settings:

<resources>
  <add match="/content/images" location="http://mycdn.com/youraccount/images"/>
  <add match="/content/css" location="http://mycdn.com/youraccount/css"/>
  <add match="/content/js" location="http://mycdn.com/youraccount/js"/>
</resources>

...and from then on those resources will be fetched from the new location instead. This is great for scenario testing locally, and the deploying to the cloud later.

木有鱼丸 2024-10-03 11:29:57

对语法的轻微调整已经对其进行了排序。

<img alt="" src="${Base.ApplicationPath}images/screenshots/myImage.jpg" />

Slight tweak of the syntax has sorted it.

<img alt="" src="${Base.ApplicationPath}images/screenshots/myImage.jpg" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文