RESOLVEURL / ResolveClientUrl等效Asp.Net剃刀? [英] ResolveUrl/ResolveClientUrl equivalents for Asp.Net Razor?

查看:232
本文介绍了RESOLVEURL / ResolveClientUrl等效Asp.Net剃刀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用&LT启动;%:Url.Content(〜/网站/等等)%GT; 语法标准,CS​​S,JScript和图片网址 - 解决了很多问题,确实;并且它至少是一致beween WebForms和剃刀页(不是所有的开发者我的会做剃须刀,但他们仍然会工作这个平台,我制作了)。

So I've started using the <%: Url.Content(~/site/blah) %> syntax as standard for CSS, JScript and Image urls - solves a lot of issues indeed; and it's at least consistent beween WebForms and Razor pages (not all of my devs will be doing Razor, and yet they will still be working on this platform I've produced).

不过,对于东西,我做的那一刻我真的可以做一个方式,采取写在剃刀页和相对URL,在运行时,它解析为正确的服务器端的文件,将其前返回到客户端的绝对URL。 Url.Content 并没有对相对URL东西。

However, for something that I'm doing at the moment I could really do with a way to take a relative Url written in a Razor page and, at run time, resolve it to the correct server side file, before turning it back into an absolute Url for the client. Url.Content doesn't do anything with relative Urls.

所以,基本上,我想无论是的等效 RESOLVEURL ResolveClientUrl 在剃刀水平。

So, basically, I want either an equivalent of ResolveUrl or ResolveClientUrl at the Razor level.

我想这能更简洁(并且更耐重命名)资源路径在我的一些MVC的意见,这可能是几个文件夹再向下从根和其内容的文件夹会更容易EX pressed为相对路径 - 这样我就可以有:

I would like this to enable terser (and more tolerant to renaming) resource paths in some of my MVC views, which can be a few folders further down from the root, and whose content folder would be more easily expressed as a relative path - so I could have:

文件夹\\文件夹\\意见\\共享\\ layout.cshtml 结果
和结果
文件夹\\文件夹\\内容\\的site.css

(我推断使用布局页面的,另外,以镜像的那种由RESOLVEURL处理的问题和重基础即WebForms的那样)

(I've inferred the use of a layout page, also, to mirror the kind of issues that are addressed by ResolveUrl and the re-basing that WebForms does)

使用 Url.Content ,因为它是,我需要指定的完整路径:

Using Url.Content as it is, I would need to specify the full path:

Url.Content(〜/文件夹/文件夹/内容/的site.css)

但我想是

Url.Content(../../的site.css)

和有工作,当然,不管有多少路径有在当前请求的路线。

And have that work, of course, regardless of how many paths there are in the current request's route.

当然,我能得到这个在WebForms的工作,如果我沟Url.Content呼叫,只依靠URL垫底。

Of course I can get this to work in WebForms, if I ditch the Url.Content call and just rely on url rebasing.

是否有剃刀任何等效?

推荐答案

您可以尝试使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.webpages.webpagerenderingbase.href.aspx\">WebPageRenderingBase.Href方法是这样

You could try using WebPageRenderingBase.Href method like this

@Href("../../site.css")

这篇关于RESOLVEURL / ResolveClientUrl等效Asp.Net剃刀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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