Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C上呈现html时删除双引号# public ActionResult ReadConfig() { IEnumerable text=System.IO.File.ReadLines(@“C:\Users\nys\source\repos\WebApplication4\WebApplication4\Configs\Json_test.txt”); IEnumerator en=text.GetEnumerator(); 变量X=@“_C#_Asp.net Mvc - Fatal编程技术网

C# 在C上呈现html时删除双引号# public ActionResult ReadConfig() { IEnumerable text=System.IO.File.ReadLines(@“C:\Users\nys\source\repos\WebApplication4\WebApplication4\Configs\Json_test.txt”); IEnumerator en=text.GetEnumerator(); 变量X=@“

C# 在C上呈现html时删除双引号# public ActionResult ReadConfig() { IEnumerable text=System.IO.File.ReadLines(@“C:\Users\nys\source\repos\WebApplication4\WebApplication4\Configs\Json_test.txt”); IEnumerator en=text.GetEnumerator(); 变量X=@“,c#,asp.net-mvc,C#,Asp.net Mvc,”; 列表T=新列表(); while(en.MoveNext()) { X+=正常电流; T.Add(en.当前); T.添加(“\n”); } X+=“”; var dat=新数据{context=X}; ViewBag.context=T; 返回视图(dat); } 因此,这里的代码应该从一个文件中读取,并在html页面中以文本的形式输出 public ActionResult ReadConfig() { IEnumerable<string> text = Sys

”; 列表T=新列表(); while(en.MoveNext()) { X+=正常电流; T.Add(en.当前); T.添加(“\n”); } X+=“

”; var dat=新数据{context=X}; ViewBag.context=T; 返回视图(dat); } 因此,这里的代码应该从一个文件中读取,并在html页面中以文本的形式输出

public ActionResult ReadConfig()
{
    IEnumerable<string> text = System.IO.File.ReadLines(@"C:\Users\nys\source\repos\WebApplication4\WebApplication4\Configs\Json_test.txt");
    IEnumerator<string> en = text.GetEnumerator();
    var X = @"<p>";
    List<string> T = new List<string>();
    while (en.MoveNext())
    {
        X += en.Current;

        T.Add(en.Current);
        T.Add("\n");
    }
    X += "</p>";
    var dat = new data { context = X };
    ViewBag.context = T;

    return View(dat);
}
@model WebApplication4.Models.data
@{
ViewBag.Title=“ReadConfig”;
}
ReadConfig
@foreach(ViewBag.context中的字符串a)
{
@Html.Raw(a)

}
html没有打印出格式化的文本,但我看到了双引号内的文本

如何保留文本文件中文本的间距和格式,并将其直接输出到html文件

@model WebApplication4.Models.data
@{
    ViewBag.Title = "ReadConfig";
}

<h2>ReadConfig</h2>
<div>
    @foreach(string a in ViewBag.context)
    {
        @Html.Raw(a)
        <br />
    }
</div>

请尝试使用保留空格和换行符的
Pre
标记
string filepath = Server.MapPath(your text file path);
string content = string.Empty;

using (var stream = new StreamReader(filepath)) {
  content = stream.ReadToEnd();
}

ViewBag.context = content;