在我的程序中,我已经把,
<%: Html.EditorFor(m => m.EducationData
, "~/Views/HTML/Shared/EditorTemplates/Foo/CustomTemplate.ascx")%>
但它不会从我提供的路径加载编辑器模板。我在一些例子中看到过,link他们为模板提供了自定义路径。任何人都可以提出建议吗?或者 MVC2 是否支持编辑器模板的自定义路径?或者有没有办法自定义 web.config 或某些配置,以便我可以更改默认模板位置???
最佳答案
我想你的文件夹太多了。使用 EditorTemplates 和 DisplayTemplates 时应遵循特定约定。尝试将您的模板放在此文件夹中,它应该可以工作:
"~/Views/Shared/EditorTemplates/CustomTemplate.ascx"
更新:
并非所有的编辑器模板都需要进入共享文件夹。您也可以将特定于 Controller 的模板放入特定于 Controller 的文件夹中:
"~/Views/Home/EditorTemplates/CustomTemplate.ascx"
关于asp.net-mvc - Html.EditorFor 不加载自定义模板路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11719794/