Read on the html page in asp.net mvc

I am migrating through a website from asp.

I have one page on which I cannot figure out how to transfer it.

The page is dynamic in the sense that it is read on other html-pages and places the content on the main page of the "container". There are sections in the middle of the asp page as shown below.

<%
Dim fso1, f11, ts1, s1  
Const ForReading1 = 1  
Set fso1 = CreateObject("Scripting.FileSystemObject")   
Set ts1 = fso1.OpenTextFile("" & Server.MapPath("newsletters/welcome.html") & "",     ForReading)  
s1 = ts1.ReadAll  
Response.Write s1  
ts1.Close  
set fso1 = nothing  
set f11 = nothing  
set ts1 = nothing  
set s1 = nothing  
%>  

Any suggestions in ASP.net MVC for a better way to read on other html pages and bind them to pageview.

+3
source share
3 answers

, HTML, . - , .ascx. Html.RenderPartial . HtmlHelper, RenderPartial, , .

Ex1:

 <% Html.RenderPartial( "welcome.ascx" ); %>

Ex2:

 <% Html.RenderHtml(  Server.MapPath( "newletters/welcome.html" ) ); %>

, . , . . , - :

 public static class MyHtmlHelperExtensions
 {
      public static void RenderHtml( this HtmlHelper helper, string path )
      {
           var reader = new StreamReader( path );
           var contents = reader.ReadToEnd();
           helper.ViewContext.HttpContext.Response.Write( contents );
      }
  }

, .

+5

.Net, File.ReadAllText.

<%= File.ReadAllText(Server.MapPath("newsletters/welcome.html")) %>
0

You should write like this:

string html = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("~/htm/external/header.htm"));
0
source

Source: https://habr.com/ru/post/1712988/


All Articles