2011-10-12 2 views
4

확장자가 UrlHelper이므로 모든 페이지에서 사용할 것입니다. 이 확장 프로그램을 사용하지 않고이 확장 프로그램을 참조 할 수있는 방법이 있습니까? 나는 모든 페이지 "CHTML"chtml 페이지에서 참조없이 UrlHelper의 확장자 사용

의 "MySite.Web.MVC.Extender"를 호출하지 않도록 할

@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" /> 
... 

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

감사합니다.

답변

6

<add namespace="MySite.Web.MVC.Extender" /> ~ <system.web.webPages.razor>/<pages>/<namespaces>Views/Web.config에 넣으십시오.