如何查看在ASP.NET MVC(不是剃刀)的局部视图HTML文件

问题描述:

我在我所创建如下的局部视图的应用程序:

I have an application in which I have created a partial view as below:

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

和我父视图具有以下code:

and my parent view has the following code:

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

现在,我想在局部视图中打开HTML文件。我不知道该怎么做。快速样品code将是非常美联社preciated。

Now, I want to open an HTML file in the partial view. I am not sure how to do it. Quick sample code will be highly appreciated.

视图不支持服务器端包含指令或相似。你最好的选择将是创建一个动作结果返回标记为ContentResult类型。

Views do not support server side include directives or similar. Your best bet would be to create an action result that returns the markup as a ContentResult.

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

然后在您的视图:

Then in your view:

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

完全即兴,但你明白了一点:调用服务器端的操作来获取您的标记,或者通过在previous操作结果的执行模型提供它

Totally off the cuff, but you get the point: invoke a server side action to retrieve your markup, or alternatively deliver it via the Model on the previous Action Result execution.