ASP.NET MVC 获取视图的最后修改日期/文件信息
我需要在工作申请的每一页上注明最后修改日期。我曾经通过引用 <%= LastModified %> 来做到这一点位于我的 WebForms 母版页的底部,它将返回当前 .aspx 页面的最后修改日期。我的代码甚至会检查关联的 .aspx.cs 文件,比较上次修改日期,并返回最近的日期。
有谁知道是否可以读取 MVC 视图的 FileInfo?如果可能的话,我想将其包含在母版页中。
我有一个基本控制器,已全部接线并准备就绪。我需要知道的是如何访问当前视图的 FileInfo。
namespace MyMVCApp.Controllers
{
public abstract class SiteController : Controller
{
public SiteController()
{
ViewData["modified"] = NEED TO GET FILEINFO OF CURRENT VIEW HERE;
}
}
}
I'm required to include the last modified date on every page of my applications at work. I used to do this by including a reference to <%= LastModified %> at the bottom of my WebForms master page which would return the last modified date of the current .aspx page. My code would even check the associated .aspx.cs file, compare the last modified dates, and return the most recent date.
Does anyone know if you can read the FileInfo of a MVC View? I would like to include it in the master page, if possible.
I have a base controller that all wired up and ready to go. All I need to know is how to access the FileInfo of the current view.
namespace MyMVCApp.Controllers
{
public abstract class SiteController : Controller
{
public SiteController()
{
ViewData["modified"] = NEED TO GET FILEINFO OF CURRENT VIEW HERE;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你需要知道View的物理文件,只有在处理视图的时候才知道,所以我们把工作推迟到那时:
在视图文件的底部,只需添加:
注意:它必须在视图文件中你想要的日期。如果您将其放入布局文件中,它将为您提供该文件的日期。 将日期添加到页脚
但是,您可以使用布局中的
section
In View:中:
You need to know the physical file of the View, which is only known when the view is being processed, so we delay the work until then:
At the bottom of the view file, just add:
NOTE: It must be in the view file you want the date for. If you put it in the layout file, it will give you the date of that file. However, you can get the date into the footer using a
section
In View:
in layout:
以下内容将为您提供上次写入视图的日期:
注意到我使用了 ViewBag 而不是 ViewData。
The following will give you the date of the last time the view was written:
Noticed that I used ViewBag instead of ViewData.
试试这个:
Try this: