项目下添加App_Code 文件夹(手动添加重命名)

添加 Style.cshtml

基于 helper类 写通用方法

@using System.Web.Mvc;
@using WebMatrix.Data;//这个要手动拷贝到bin目录下 不知道为什么添加引用后不自动过去
@helper Script(string scriptName, UrlHelper Url) { <script src="@Url.Content(scriptName)" type="text/javascript"></script> } @helper Css(string cssName, UrlHelper Url) { <link href="@Url.Content(cssName)" rel="stylesheet" type="text/css" /> }

 然后其他.cshtml调用方法

@Style.Css("/offerstyle/css/offer-manage.css", this.Url)

@Style.Script("/script/formValidator.js", this.Url)

这样就不用每次都写

<script src="@Url.Content("xxxxxx")" type="text/javascript"></script>了

相关文章:

  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2021-12-01
  • 2021-09-16
  • 2021-12-12
  • 2021-07-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
相关资源
相似解决方案