How do you include .html or .asp file using razor?

2019-01-22 06:39发布

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" -->"

14条回答
聊天终结者
2楼-- · 2019-01-22 07:04

Just do:

@Html.Partial("_SliderPartial")

while "_SliderPartial" is your "_SliderPartial.cshtml" file and your fine.

查看更多
冷血范
3楼-- · 2019-01-22 07:04

In my _Layout.cshtml I added following line:

@Html.Partial("InsertHelper")

Then I created InsertHelper.aspx in my Shared folder with this content:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<!--#include VIRTUAL="/ViewPage1.aspx"-->
查看更多
登录 后发表回答