【问题标题】:Custom ViewEngine, but still be able to use HtmlHelper editables?自定义 ViewEngine,但仍然可以使用 HtmlHelper 可编辑项?
【发布时间】:2012-11-08 23:01:34
【问题描述】:

如果我理解这个权利.. 剃刀视图引擎被指定为只允许默认路径的 HtmlHelper 可编辑.. 但是如果我更改或扩展引擎应该查找我的部分视图的路径然后想要能够在其中一个部分中使用 Html.EditorFor() ......无论如何让 Html.EditorFor 也可以使用此自定义路径?

【问题讨论】:

    标签: c# asp.net-mvc razor viewengine


    【解决方案1】:

    是的,您仍然可以使用 Html.EditorFor,因为他们只会使用所有您的视图引擎来解析您正在寻找的视图。如果您想查看如何使用新路径创建自己的视图引擎的示例,请查看我的一个项目中的这个视图引擎。

    https://github.com/stevehodgkiss/restful-routing/blob/master/src/RestfulRouting/ViewEngines/RestfulRoutingRazorViewEngine.cs

    public class RestfulRoutingRazorViewEngine : RazorViewEngine
    {
        public RestfulRoutingRazorViewEngine()
        {
            AreaMasterLocationFormats = new[] {
                                                  "~/Views/{2}/{1}/{0}.cshtml",
                                                  "~/Views/{2}/{1}/{0}.vbhtml",
                                                  "~/Views/{2}/Shared/{0}.vbhtml",
                                                  "~/Views/{2}/Shared/{0}.cshtml",
                                              };
    
            AreaViewLocationFormats = new[] {
                                                "~/Views/{2}/{1}/{0}.cshtml",
                                                "~/Views/{2}/{1}/{0}.vbhtml",
                                                "~/Views/{2}/Shared/{0}.cshtml",
                                                "~/Views/{2}/Shared/{0}.vbhtml",
                                            };
    
            AreaPartialViewLocationFormats = AreaViewLocationFormats;
        }
    }
    

    我仍然使用 EditorFor 来确定编辑器和显示模板的视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      • 2016-11-08
      • 1970-01-01
      • 2019-02-14
      • 2011-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多