سؤال

Why doesn't this work?

@{
    ViewBag.Title = "Website Account Manager";
}

<h2>@ViewBag.Message</h2>
<p>
@{
    System.IO.StreamReader myreader = new System.IO.StreamReader("../htdocs/websiteaccounts/Views/Home/index.htm");
    myreader.ReadToEnd();
    myreader.Close();
}
</p>

I just want the index.htm file to show in the body of my cshtml file above, but it doesn't show in the body. Everything else loads fine, just that problem there.

هل كانت مفيدة؟

المحلول

please try this

string path = AppDomain.CurrentDomain.BaseDirectory;
    System.IO.StreamReader myreader = new System.IO.StreamReader(path +  "MyTest\\randerhtml.html");
    string s = myreader.ReadToEnd();
    myreader.Close();
    @(new HtmlString(s))
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top