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?
Render actions are methods that the view calls back in the controller. A strong design point about MVC is the neat separation of controller and view. In this regard, render actions just break this separation. Render actions are effective to use; balancing design with effective solutions is the developer's job.
The Render method is responsible for creating the text and markup that is sent to the client browser. The default Render method calls RenderChildren to write the text and markup for the controls contained on the page.
ASP.NET MVC is a web application framework developed by Microsoft that implements the model–view–controller (MVC) pattern. It is no longer in active development. It is open-source software, apart from the ASP.NET Web Forms component, which is proprietary. ASP.NET MVC.
You can't use Html.Partial
for this.It is a special helper method for rendering Partial Views. Instead you can add an Action
like this:
[ChildActionOnly] public ActionResult GetHtmlPage(string path) { return new FilePathResult(path, "text/html"); }
And you can call it from your View
with using Html.Action
helper Method:
@Html.Action("GetHtmlPage","controllername", new { path = "~/Test/main.html" })
I think it's a better solution: Use WriteFile
from the Response
object
@Response.WriteFile(pathToMyHtmlFile)
taken from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With