简体   繁体   English

“懒惰”MVC5 Razor执行 - ASP.NET(优化)

[英]“Lazy” MVC5 Razor execution - ASP.NET (optimization)

We wrote razor extension method to use it in vbhtml view which make translations of static, non list, non generated elements ie titles, static navigation elements and so on : 我们编写了razor扩展方法,在vbhtml视图中使用它,它使静态,非列表,非生成元素的翻译,即标题,静态导航元素等:

<h1>@Html.GetTagText("aaa"(real string), cultureCode, translationContext)</h1>

with this idea we generate X calls to DB, every time we call this method. 有了这个想法,我们每次调用这个方法时都会生成对DB的X调用。

Question : Is there any Event raised by Razor Engine before transform and After transform, or somekind of entrypoint in ASP.NET page lifecycle (pre render, post render) which will allow us to : 问题:Razor Engine在转换和After转换之前是否引发了任何事件,或者是ASP.NET页面生命周期中的某些入口点(预渲染,后渲染),这将允许我们:

  1. Collect all getTagText calls to list 将所有getTagText调用收集到列表中
  2. do rest of razor work 做其余的剃刀工作
  3. give back all translations in one DB shoot 在一次DB拍摄中回馈所有翻译
  4. put/replace correct translations into correct places 将正确的翻译放入/替换到正确的位置

or maybe i am thinking totaly wrong, and razor isn't good place to do that kind of "magic" ? 或者我认为完全错了,剃刀不是做那种“魔术”的好地方? I need generic idea, something that i will write once, to do not reproduce this in every controller. 我需要通用的想法,我会写一次,不要在每个控制器中重现这一点。

I would suggest you handle this kind of work in your controller. 我建议你在你的控制器中处理这种工作。 Create a view model where you can place your translated text for the fields you need translated and populate the view model in the controller. 创建一个视图模型,您可以在其中放置需要翻译的字段的翻译文本,并在控制器中填充视图模型。

I do not think there are any events raised by an MVC view. 我不认为MVC视图提出任何事件。 I have tried to hook into these kinds of events to measure the page rendering time and could not find any such hooks. 我试图挂钩这些事件来测量页面呈现时间,但找不到任何这样的钩子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM