asp.net-mvc-3 – 在chtml页面中使用UrlHelper的扩展而不引用
发布时间:2020-12-16 06:46:23 所属栏目:asp.Net 来源:网络整理
导读:我有一个UrlHelper的扩展,我将在每个页面上使用chtml.我是否有任何方法可以参考此扩展而无需使用它? UrlExtender.cs using System;using System.IO;using System.Web.Mvc;namespace MySite.Web.MVC.Extender{ public static class UrlExtender { public sta
我有一个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); } } } } 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" /> ... 我想避免在每个页面上调用“MySite.Web.MVC.Extender”“chtml” 谢谢 解决方法
添加< add namespace =“MySite.Web.MVC.Extender”/>到< system.web.webPages.razor> /< pages> /< namespaces>在Views / Web.config中.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 以编程方式获取MVC视图列表?
- asp.net-mvc – 在MVC项目中创建区域
- asp.net mvc 三元运算符改变样式
- asp.net如何跳转到其他文件夹下的页面
- asp.net-mvc – 使用FileStreamResult删除临时文件
- asp.net-mvc-3 – 在MVC3中使用自定义的IPrincipal和IIdent
- ASP.NET设计FTP文件上传的解决方案
- asp.net-mvc – 保存为“BodyPart_3ded2bfb-40be-4183-b789
- asp.net – Glimpse让一切变得慢50倍
- asp.net-mvc – MVC @ Html.CheckboxFor在表单提交时提交tr
推荐文章
站长推荐
- asp.net-mvc-3 – 如何在输出缓存中使用动态持续
- ASP.NET开发人员真的需要关心线程安全吗?
- asp.net-mvc – 神控制器 – 如何防止它们?
- asp.net – 在Page_Load(对象发送者,EventArgs e
- asp.net-mvc – EnumDataType属性在ASP.NET MVC中
- ASP.Net的Web TWAIN扫描解决方案?
- asp.net-core – MVC 6安装为Windows服务(ASP.NE
- asp.net – 无法加载类型’site._Default'[已
- asp.net – Web窗体中的.NET MVC FileResult等价
- 验证 – ASP.NET MVC将null转换为零长度字符串
热点阅读