是否可以从浏览器中查看MVC视图结构? [英] Is it possible to see the MVC View structure from within a browser?
本文介绍了是否可以从浏览器中查看MVC视图结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从浏览器中查看MVC视图结构? 如中所示,是否可以启用某些配置,以显示从浏览器中呈现的每个视图和部分视图的文件名?
即
如果我有Index.cshtml,然后它呈现两个分部视图Content1.cshtml和Content2.cshtml,那么我希望从F12浏览器工具中查看文件名:
//Index.cshtml
<html> .....
....
//Content1.cshtml
<table> ... </table>
//Content2.cshtml
<div> ... </div>
</html>
推荐答案
您可以使用呼叫者信息属性之一。
新建ViewFileName
函数:
using System.IO;
using System.Web.Mvc;
using System.Runtime.CompilerServices;
public static class Extensions
{
public static IHtmlString ViewFileName([CallerFilePath]string filePath = "unknown")
{
return new MvcHtmlString("<!-- " + Path.GetFileName(filePath) + " -->");
}
}
然后在每个常规和部分视图中调用它:
@Extensions.ViewFileName()
有关详细信息,请查看Microsoft ASP.NET团队的Caller Information (C#) documentation、Creating Custom HTML Helpers (C#) article和Print the source filename and linenumber in C# question。
这篇关于是否可以从浏览器中查看MVC视图结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文