and*_*lzo 4 urlhelper razor asp.net-mvc-3
我有一个UrlHelper的扩展,我将在每个页面上使用chtml.我是否有任何方法可以参考此扩展而无需使用它?
UrlExtender.cs
using System;
using System.IO;
using System.Web.Mvc;
namespace MySite.Web.MVC.Extender
{
public static class UrlExtender
{
public static string ContentLastWrite(this UrlHelper helper, string contentPath)
{
try
{
DateTime lastWriteTime = (new FileInfo(helper.RequestContext.HttpContext.Server.MapPath(contentPath))).LastWriteTime;
contentPath = string.Format("{0}?v={1:yyyyMMddHHmmss}", contentPath, lastWriteTime);
return helper.Content(contentPath);
}
catch
{
return helper.Content(contentPath);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
page.chtml
@using MySite.Web.MVC.Extender
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.ContentLastWrite("~/Content/Site.css")" rel="stylesheet" type="text/css" />
...
Run Code Online (Sandbox Code Playgroud)
我想避免在每个页面上调用"MySite.Web.MVC.Extender""chtml"
谢谢
添加<add namespace="MySite.Web.MVC.Extender" />到<system.web.webPages.razor>/<pages>/<namespaces>在Views/Web.config.
| 归档时间: |
|
| 查看次数: |
2229 次 |
| 最近记录: |