In my view, would like to render the contents of an HTML file as a partial view. It is giving me this error though when I add this to the .cshtml view:
@Html.Partial(Url.Content("~/Test/main.html"))
Errors:
Exception Details: System.InvalidOperationException: The partial view '/Scripts/main.html' was not found or no view engine supports the searched locations. The following locations were searched:
/Scripts/main.html
The file is physically there though. Is there a different way I should be doing this?
I think it's a better solution: Use
WriteFile
from theResponse
objecttaken from here
Follow these steps
You could use this in your cshtml view:
You can't use
Html.Partial
for this.It is a special helper method for rendering Partial Views. Instead you can add anAction
like this:And you can call it from your
View
with usingHtml.Action
helper Method:Just use an ajax request to fetch the html file output the content into your main html. Since it is an html file, it will be cached in subsequent calls and there will be no performance impact.
The simple answer is to rename the main.html file to main.cshtml which will be recognized by the Razor view engine for rendering.