2

我在 MVC4 中使用捆绑,或者更确切地说,我正在使用捆绑但不得不将其关闭。这意味着脚本和样式链接只是在单独的行上呈现,并且没有版本字符串以确保浏览器在有更新时下载最新文件。

我尝试在捆绑代码中添加版本字符串,但随后我收到一条错误消息,指出路径无效。

有没有办法将版本控制应用于已关闭捆绑的捆绑脚本文件?

4

1 回答 1

6

Here is one way to do what you want. Instead of using Scripts.Render

@Scripts.Render("~/ScriptMonkey")

you can use Scripts.RenderFormat

@Scripts.RenderFormat("<script src=\"{0}?v=" + DateTime.Now.Ticks.ToString() +"\"></script>", "~/ScriptMonkey")

That will force a download every time... or you can just put a number in there

@Scripts.RenderFormat("<script src=\"{0}?v=1\"></script>", "~/ScriptMonkey")

Though I think doing this could be a huge pain as you would be responsible for changing that variable every time a script changes.

于 2013-09-12T18:23:38.617 回答