4
我有一个UrlHelper的扩展,我将在每个页面上使用chtml。我有什么办法可以参考这个扩展,而不必使用?在chtml页面中使用UrlHelper的扩展名,但没有引用
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);
}
}
}
}
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" />
...
我想避免调用在每一页上 “CHTML”
“MySite.Web.MVC.Extender”谢谢