在我看来,想将
HTML文件的内容呈现为局部视图.当我将它添加到.cshtml视图时,它会给我这个错误:
@Html.Partial(Url.Content("~/Test/main.html"))
错误:
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
该文件实际上在那里.有不同的方式我应该这样做吗?
解决方法
你不能使用Html.Partial这是一个特殊的帮助方法来渲染局部视图.相反,您可以添加如下操作:
[ChildActionOnly] public ActionResult GetHtmlPage(string path) { return new FilePathResult(path,"text/html"); }
您可以使用Html.Action
帮助器从您的View中调用它方法:
@Html.Action("GetHtmlPage","controllername",new { path = "~/Test/main.html" })