加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 查找:DisplayTemplates速度

发布时间:2020-12-16 06:59:41 所属栏目:asp.Net 来源:网络整理
导读:我在新的MVC4站点上安装了Mini-Profiler,并注意到某些Find:DisplayTemplates包括String和DateTime的等待时间很长.以下是一个例子.在另一个问题中,Sam Saffron谈到了寻找步骤 On subsequent runs it is lightning fast (unless you have something really ba
我在新的MVC4站点上安装了Mini-Profiler,并注意到某些Find:DisplayTemplates包括String和DateTime的等待时间很长.以下是一个例子.在另一个问题中,Sam Saffron谈到了寻找步骤

On subsequent runs it is lightning fast (unless you have something really bad going on)

但是每个页面加载都会发生以下情况:

http://localhost:80/SLS.Site/s/hogwarts/lunch...     2.6    +0.0
  Check School Permissions                           2.4    +2.0     1 sql   0.9
  Controller: SchoolAdmin.LunchGroupsController...   4.0    +4.5
  Find: Index                                        0.4    +8.6
  Render : Index                                    70.0    +9.1     2 sql   13.0
   Controller: SchoolAdmin.LunchGroupsController...  2.6    +12.3
   Find: BuildingTree                                0.4    +14.9
   Render partial: BuildingTree                      4.4    +15.4    1 sql   3.2
   Controller: SchoolAdmin.LunchGroupsController...  3.3    +20.2
   Find: Teachers                                    0.6    +23.6
   Render partial: Teachers                          4.3    +24.3    1 sql   2.4
   Find: DisplayTemplates/String                   409.3    +31.9
   Render partial: _UserContext                      0.0    +441.3
   Find: _LoginPartial                               1.2    +441.4
   Render partial: _LoginPartial                     0.2    +442.6
                                                                     3.9 % in sql

有什么想法吗?

编辑

我有4个区域设置,所以我认为它遍历所有目录寻找匹配,所以我删除了2个区域并具有相同的行为.

解决方法

我有完全相同的问题……经过一番搜索我发现我在使用:

@DisplayFor(x => x.StringProperty);

在考虑了它之后,发现了自己制作一些模板后所有DisplayFor / EditorFor方法的工作原理,这没有任何意义.

(关于DisplayFor / EditorFor如何工作的一些解释)

使用DisplayFor / Editor时,MVC获取对象类型,然后在Views / ControllerName / DisplayTemplates目录中搜索与该类型同名的视图,在这种情况下,它搜索Views / ControllerName / DisplayTemplates / String.cshtml .由于它不存在,它也在Shared / DisplayTemplates视图目录中执行相同的操作,同样,它也不存在.

(接下来就是猜测)

我认为,由于找不到相关的显示/编辑器模板,它会在对象上执行ToString()作为故障转移.

因为你只是显示一个String类型,所以不使用DisplayFor(x => StringProperty)并使用@ Model.StringProperty是有意义的,它不会导致MVC搜索DisplayTemplate,只是将其渲染为一个字符串,它无论如何都要做.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读