Tru*_*an1 23 asp.net asp.net-mvc razor asp.net-mvc-4
在我看来,想要将HTML文件的内容呈现为部分视图.当我将它添加到.cshtml视图时,它给了我这个错误:
@Html.Partial(Url.Content("~/Test/main.html"))
Run Code Online (Sandbox Code Playgroud)
错误:
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
Run Code Online (Sandbox Code Playgroud)
虽然文件在那里.我应该采取不同的方式吗?
Sel*_*enç 33
你无法使用它Html.Partial.它是一种用于渲染部分视图的特殊辅助方法.相反,您可以添加Action如下:
[ChildActionOnly]
public ActionResult GetHtmlPage(string path)
{
return new FilePathResult(path, "text/html");
}
Run Code Online (Sandbox Code Playgroud)
您可以View使用Html.Action帮助程序从您的方法调用它:
@Html.Action("GetHtmlPage","controllername", new { path = "~/Test/main.html" })
Run Code Online (Sandbox Code Playgroud)
跟着这些步骤
我认为这是一个更好的解决方案:WriteFile从Response对象中使用
@Response.WriteFile(pathToMyHtmlFile)
Run Code Online (Sandbox Code Playgroud)
取自这里
| 归档时间: |
|
| 查看次数: |
48775 次 |
| 最近记录: |