你如何包含的.html或使用剃刀.asp文件? [英] How do you include .html or .asp file using razor?

查看:209
本文介绍了你如何包含的.html或使用剃刀.asp文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用服务器端包含的Razor视图引擎包含的.html或.asp文件?我们有一个.html文件和包含用于所有的websitse的网站菜单.asp文件。目前我们使用服务器端包括我们所有的网站,这样我们只需要改变mensu在一个地方。

我在我的_Layout.cshtml

正文下面code

 <身体GT;
<! - #包括虚拟=/服务器端/菜单/ MainMenu.asp - >
<! - #包括虚拟=/服务器端/菜单/ library_menu.asp - >
<! - #包括虚拟=/组合/服务器端/菜单/ portfolio_buttons_head.html - >
@RenderBody()
< /身体GT;

相反,包括文件的内容,如果我做了查看源代码,我看到了文字文本的。

 <! - #包括虚拟=/服务器端/菜单/ MainMenu.asp - >
    <! - #包括虚拟=/服务器端/菜单/ library_menu.asp - >
    <! - #包括虚拟=/组合/服务器端/菜单/ portfolio_buttons_head.html - >中


解决方案

剃刀不支持服务器端包含。最简单的解决办法是复制菜单标记到您的网页_Layout.cshtml

如果你只需要包含.html文件,你也许可以编写从磁盘中读取该文件,并写了一个输出自定义函数。

不过,因为你还希望包括.asp文件(可能包含任意服务器端code)上述方法将无法正常工作。你就必须有办法执行.asp文件,捕捉生成的输出,并写入到您的CSHTML文件的响应。

在这种情况下,我会去的复制粘贴+方法

Is it possible to use server side include in Razor view engine to include .html or .asp file? We have an .html file and .asp files that contain website menus that are used for all of our websitse. Currently we use server side include for all of our sites so that we only need to change the mensu in one place.

I have the following code in the body of my _Layout.cshtml

<body>
<!--#include virtual="/serverside/menus/MainMenu.asp" -->   
<!--#include virtual="/serverside/menus/library_menu.asp" -->
<!--#include virtual="/portfolios/serverside/menus/portfolio_buttons_head.html" -->
@RenderBody()
</body>

Instead of including the content of the file, if I do a view source, I see the literal text.

" <!--#include virtual="/serverside/menus/MainMenu.asp" --> 
    <!--#include virtual="/serverside/menus/library_menu.asp" -->
    <!--#include virtual="/portfolios/serverside/menus/portfolio_buttons_head.html" -->"

解决方案

Razor does not support server-side includes. The easiest solution would be copying the menu markup into your _Layout.cshtml page.

If you only needed to include .html files you could probably write a custom function that read the file from disk and wrote the output.

However since you also want to include .asp files (that could contain arbitrary server-side code) the above approach won't work. You would have to have a way to execute the .asp file, capture the generated output, and write it out to the response in your cshtml file.

In this case I would go with the copy+paste approach

这篇关于你如何包含的.html或使用剃刀.asp文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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