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

后端 未结 14 1488
说谎
说谎 2020-12-14 01:09

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

14条回答
  •  离开以前
    2020-12-14 01:33

    Sorry guys for bit old answer but I found some way to attach asp file with razor. Of course you need to do some trick but it works! First of all I created .NET MVC 3 application.

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

    ViewPage1.aspx is locaited in my root directory, and has just simple if to check whether it works:

    <%
    string dummy;
    dummy="nz";
    %>
    
    <% if (dummy == "nz") { %>
    nz indeed
    <% } else { %>
    not nz
    <% } %>
    

    And it works!

    Razor is able to render partials with different ViewEngine, and that's why this example is working.

    And one more thing: remember to not add following line in both aspx files:

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

    You can add it only once! Hope it helps!

提交回复
热议问题