Render HTML file in ASP.NET MVC view?

Viewed 62507

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?

7 Answers

A total different way is just load the file in javascript

<div id="loadId">
</div>

<script>
    $(document).ready(function () {
        $('#loadId').load('filepath');
    });
</script>

You can set the filepath in the controller, or put it in the model, if you want, and use:

$('#loadId').load('@ViewBag.filepath');
Related