1

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>

and my parent view has the following code:

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

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.

2
  • Could you elaborate more about opening the HTML file? I don't really get what you are trying to do.. Commented May 22, 2014 at 17:52
  • I have an html file in my Contents folder. I want to open it on a partial view after the parent view buttons. Commented May 22, 2014 at 17:55

1 Answer 1

1

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")) %>

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.