public JsonResult GetView(string suoshu)
{
string url = "";
Dictionary<string,string> strlist = new Dictionary<string,string>();
if (suoshu == "zf")
{
url = Server.MapPath("~/Areas/X/Views/Mesf");//返回物理路径
}
else if(suoshu=="xxy")
{
url = Server.MapPath("~/Areas/X/Views/Mesy");//返回物理路径
}
else
{
return Json(null, JsonRequestBehavior.AllowGet);
}
//初始化
DirectoryInfo dir = new DirectoryInfo(url);
//返回文件类
FileInfo[] fi = dir.GetFiles();
if (fi.Length > 0)
{
//循环获取文件信息
foreach(FileInfo dChild in fi)
{
if (dChild.Extension.ToLower() == ".cshtml")
{
strlist.Add(dChild.Name.Substring(0, dChild.Name.IndexOf(‘.‘)), dChild.Name.Substring(0, dChild.Name.IndexOf(‘.‘)));
}
}
}
var json =new {
rows=(from r in strlist
select new
{
Id = r.Key,
Name = r.Value
}).ToArray()
};
return Json(json,JsonRequestBehavior.AllowGet);
}
这是我的一个获取mvc某个视图文件下所有视图的方法
原文地址:https://www.cnblogs.com/Wxinchun/p/8871965.html