T4MVC 不支持 DisplayTemplates 和 EditorTemplates
当我在视图中使用以下内容时,我注意到了这一点:
<% Html.RenderPartial(MVC.Shared.Views.EditorTemplates.ClientOnDocuments); %>
上面的行仅返回视图的名称,因此在本例中为 ClientOnDocuments
。然后,默认视图引擎启动并尝试在当前视图的文件夹和共享文件夹中查找 ClientOnDocuments.ascx
,但不在 DisplayTemplates
和 EditorTemplates
中查找> 文件夹。
由于我对 T4MVC 的使用已经很深入了,所以我不想转储它或混合不同样式的引用视图(例如,如果我们提供模板的路径,则上述内容有效)。
原因在于 T4MVC 生成的这段代码:
public class ViewNames {
...
public readonly string FirmHeader = "~/Views/Shared/FirmHeader.ascx";
public readonly string PostsSelector = "~/Views/Shared/PostsSelector.ascx";
static readonly _DisplayTemplates s_DisplayTemplates = new _DisplayTemplates();
public _DisplayTemplates DisplayTemplates { get { return s_DisplayTemplates; } }
public partial class _DisplayTemplates{
public readonly string ClientOnDocuments = "ClientOnDocuments";
public readonly string DateTime = "DateTime";
}
static readonly _EditorTemplates s_EditorTemplates = new _EditorTemplates();
public _EditorTemplates EditorTemplates { get { return s_EditorTemplates; } }
public partial class _EditorTemplates{
public readonly string ClientOnDocuments = "ClientOnDocuments";
public readonly string DateTime = "DateTime";
public readonly string PostCode = "PostCode";
}
您可以看到,使用共享根中包含的视图一切都很好,但显然它不能很好地处理子文件夹。
我知道我可以更改 T4MVC 模板文件,但实际上希望 David Ebbo 回复他是否打算改变/纠正这个。
希望他也能这么做,至少我十二月在这里见过他。
I've noticed this when I used the following in my view:
<% Html.RenderPartial(MVC.Shared.Views.EditorTemplates.ClientOnDocuments); %>
The line above returns just the name of the view, so in this case ClientOnDocuments
. The default view engine then kicks in and tries to find ClientOnDocuments.ascx
in the current view's folder and in the Shared folder but not in DisplayTemplates
and EditorTemplates
folder.
Since I've gone pretty far with my use of T4MVC I don't want to dump it or mix different styles of referencing views (for instance, the above works if we provide the path to the template).
The reason lies in this code that T4MVC generates:
public class ViewNames {
...
public readonly string FirmHeader = "~/Views/Shared/FirmHeader.ascx";
public readonly string PostsSelector = "~/Views/Shared/PostsSelector.ascx";
static readonly _DisplayTemplates s_DisplayTemplates = new _DisplayTemplates();
public _DisplayTemplates DisplayTemplates { get { return s_DisplayTemplates; } }
public partial class _DisplayTemplates{
public readonly string ClientOnDocuments = "ClientOnDocuments";
public readonly string DateTime = "DateTime";
}
static readonly _EditorTemplates s_EditorTemplates = new _EditorTemplates();
public _EditorTemplates EditorTemplates { get { return s_EditorTemplates; } }
public partial class _EditorTemplates{
public readonly string ClientOnDocuments = "ClientOnDocuments";
public readonly string DateTime = "DateTime";
public readonly string PostCode = "PostCode";
}
You can see that with the view contained in Shared root everything is fine but apparently it doesn't handle subfolders well.
I know I could change the T4MVC template file but would actually like a response from David Ebbo on whether he is going to change/correct this.
Hopefully he follows SO, at least I saw him here in December.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有趣的是,这种不同的行为是在另一个用户遇到问题后故意采取的。在 T4MVC.settings.t4 中查找此内容:
所以通常情况下,子文件夹会获得完整路径,但只有这两个文件夹不会。
我认为区别在于用户调用 DisplayFor/EditorFor 来渲染它们,而您调用 RenderPartial。
无论如何,由于这是在设置文件中而不是主模板中,因此如果您不希望出现这种行为,您可以简单地更改列表,即
希望这会有所帮助! :)
Interestingly, this different behavior was put in deliberately after another user ran into issues. Look for this in the T4MVC.settings.t4:
So normally, sub folders get full paths, but only those two don't.
I think the difference was that that user was calling DisplayFor/EditorFor to render those, while you are calling RenderPartial.
In any case, since this is in the settings file and not the main template, you can simply change the list if you don't want that behavior, i.e.
Hope this helps! :)