Using an extension of UrlHelper without reference in chtml page
I have an extension of UrlHelper, I'll use on every page chtml. Do I have any way to refer to this extension without having to do it by using?
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
{
r开发者_如何学Ceturn 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" />
...
I want to avoid calling "MySite.Web.MVC.Extender" on every page "chtml"
Thanks
Add <add namespace="MySite.Web.MVC.Extender" />
to <system.web.webPages.razor>/<pages>/<namespaces>
in Views/Web.config
.
精彩评论