Hello! I have this question. If I want to render another view on the view, then I can use the following code:

@Html .Partial("Myiew") 

However, if I want to render not a presentation, but a certain html-page (namely, the page, and not some other presentation) then when I write this:

 @Html .Partial("MyPage.html") 

I’m getting an error The partial view 'MyPage.html' was not supported or supported by the engine.

Given that the MyPage.html page definitely exists, and there are no errors in the path to it (even the resharper testifies to this). How can I render this html page on my presentation? Thank you in advance

    1 answer 1

    The PartialExtensions.Partial(HtmlHelper, string) method PartialExtensions.Partial(HtmlHelper, string) takes the name partial view. As you understand, "MyPage.html" not: it is just the name of the file. Having received such a value at the input, the view engine will search for the following files in this order (for the Razor view engine):

     ~/Views/[ControllerName]/MyPage.html.cshtml ~/Views/[ControllerName]/MyPage.html.vbhtml ~/Views/Shared/MyPage.html.cshtml ~/Views/Shared/MyPage.html.vbhtml 

    I see two ways to do what you need:

    1) Create a helper method that will read the contents of the specified file and return an HTML-encoded string. The easiest way:

     public static class MyHtmlHelper { public static MvcHtmlString RenderFile(string virtualPath) { var physicalPath = HostingEnvironment.MapPath(virtualPath); var fileContent = File.ReadAllText(physicalPath ); return new MvcHtmlString(fileContent); } } 

    You can then use this in the presentation code:

     @MyHtmlHelper.RenderFile("MyPage.html") 

    2) Method number 2 is not even a way, but rather a "workaround". You can create a copy of your html-page and save it as a view-file. However, there is an obvious drawback - if you need to change this page you will have to change it in two places.