ASP.NET C# 打印出 HTML 内容

本文关键字:HTML 内容 打印 NET ASP | 更新日期: 2023-09-27 17:56:56

我正在为一个大学项目学习.NET,已经对PHP有扎实的知识。我想了解如何在.NET中打印出html内容,就像我在PHP中所做的那样。

PHP示例:

<?php
    $array = array("foo", "bar", "hello", "world");
    for($i=0; $i<count($array); $i++) {
       echo "<p id='"$i'">This is paragraph $i.</p>"; 
    }
?>

这是我试图实现和理解的一个简单例子。我将如何在 ASP.NET 中执行上述操作?

感谢您的帮助。

ASP.NET C# 打印出 HTML 内容

把这个写在你的页面上

  <%   
  var array = new string[]{"foo", "bar", "hello", "world"};
  Response.ContentType = "text/html";
  for(int i = 0; i < array.Length; i++) 
  {
  Response.Write(string.Format("<p id='"{0}'">This is paragraph {0}.</p>",i)); 
  }
  %>

执行以下操作:

<%
   var array = new string[]{"foo", "bar", "hello", "world"};
   Response.ContentType = "text/html";
   for(int i = 0; i < array.Length; i++) {
      Response.Write(string.Format("<p id='"{0}'">This is paragraph {0}.</p>",i)); 
   }
%>