【发布时间】:2013-11-06 02:02:07
【问题描述】:
mvc4,剃刀视图引擎。如果在调试模式下,像这样包含部分的 sn-p 会留下注释说明它注入的部分,这将很有用。有没有我找不到的扩展点?显然,我可以在部分视图中输入此评论,但这听起来 WAAYY 工作量太大,对任何人都没有乐趣。
index.cshtml
<div class="somecontainer">
@foreach(var thing in Model.Things) {
Html.Partial("ThingPartial",thing)
}
</div>
ThingPartial.cshtml
@model ThingModel
<h1>@Model.Name<h1>
<p>@Model.Description</p>
会生成这样的html
<!--razorView:things/index-->
<div class="somecontainer">
<!--partialView:ThingPartial-->
<h1>Name 1<h1>
<p>Description 1</p>
<!--partialView:ThingPartial-->
<h1>Name 2<h1>
<p>Description 2</p>
<!--partialView:ThingPartial-->
<h1>Name 3<h1>
<p>Description 3</p>
</div>
动机 我希望我的测试人员能够使用 cmets 编写更准确的错误报告,而无需我的开发人员/我做任何额外的事情!
我的想法是在 global.asax.cs 中可配置的,就像这样
ViewEngines.Engines.Clear();
RazorViewEngine viewEngineToAdd = new RazorViewEngine();
//I COMPLETELY MADE THIS LINE UP, THESE THINGS DON'T EXIST (but I want them to!
viewEngineToAdd.PreRender += (OutputStream,IView) => OutputStream.Write(@"<!--"+IView.Name+"-->")
ViewEngines.Engines.Add(viewEngineToAdd);
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-4 razor