【问题标题】:How to view HTML file in Partial View of ASP.NET MVC (not Razor)如何在 ASP.NET MVC(不是 Razor)的部分视图中查看 HTML 文件
【发布时间】:2014-05-22 17:39:50
【问题描述】:

我有一个应用程序,我在其中创建了如下部分视图:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

我的父视图有以下代码:

<div>
       <% @Html.RenderPartial("ViewerControl"); %> 
    </div>

现在,我想在局部视图中打开一个 HTML 文件。我不知道该怎么做。快速示例代码将不胜感激。

【问题讨论】:

  • 您能详细说明一下打开 HTML 文件吗?我真的不明白你想要做什么..
  • 我的 Contents 文件夹中有一个 html 文件。我想在父视图按钮之后的局部视图上打开它。

标签: c# asp.net asp.net-mvc asp.net-mvc-4


【解决方案1】:

视图不支持服务器端包含指令或类似指令。最好的办法是创建一个将标记作为 ContentResult 返回的操作结果。

public ContentResult HtmlFile() {
    return Content(File.ReadAllText(Server.MapPath("Give the path here")));
}

那么在你看来:

<%: Html.Raw(Html.Action("HtmlFile")) %>

完全即兴表演,但您明白了:调用服务器端操作来检索您的标记,或者在先前的操作结果执行时通过模型传递它。

【讨论】:

    猜你喜欢
    • 2011-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    相关资源
    最近更新 更多