从 asp.net mvc 控制器返回 js 文件
嗨,所有程序员同事,
我希望为应用程序中的每个 MVC 集都有一个单独的 js 文件
/Controllers/
-TestController.cs
/Models/
/Views/
/Test/
-Index.aspx
-script.js
,并且我希望将 js 包含在 Index.aspx 中,
<script type="text/javascript" src="<%=UriHelper.GetBaseUrl()%>/Test/Js"></script>
或者更简单地说,当我调用 http://localhost/Test/Js 在浏览器中,它会向我显示 script.js 文件
如何编写 Action控制器?我知道这必须通过 return File 方法来完成,但我还没有成功创建该方法:(
Hi all fellow programmer
I'd like to have a separate js file for each MVC set I have in my application
/Controllers/
-TestController.cs
/Models/
/Views/
/Test/
-Index.aspx
-script.js
And I'd like to include the js in the Index.aspx by
<script type="text/javascript" src="<%=UriHelper.GetBaseUrl()%>/Test/Js"></script>
Or to put it easier, when I call http://localhost/Test/Js in the browser, it will show me the script.js file
How to write the Action in the Controller? I know that this must be done with return File method, but I haven't successfully create the method :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样:
我要补充一点,你确实应该将脚本放在 Content 文件夹下,因为 MVC 是关于约定之上的配置,并且通过尝试将脚本与视图放置在一起,你就打破了约定。
How about:
I will add that you really should have your scripts under your Content folder as MVC is all about convention above configuration and by trying to place your scripts with your views you are breaking convention.
两个选项:
HTH 将 javascript 文件作为可下载文件返回。
Two options:
HTH.