T4MVC 与外部 javascript 文件一起使用
是否可以在外部js文件中使用T4MVC?
我在 cshtml 文件中包含一个 js 文件
中有以下内容,
,在 MyScript.js 中,我在函数@Url.Action(MVC.MyController.MyAction())
但它永远不会被编译为其操作名称(认为 runat 服务器会这样做)这个技巧但它没有)
我错过了什么?我也在使用 chirpy 如果有什么可以帮助的...
谢谢
Is it possible to use T4MVC in an external js file?
I include a js file in my cshtml file
and in MyScript.js i have the following in a function
@Url.Action(MVC.MyController.MyAction())
but it never get compiled to its Action name (thought that runat server would do that trick but it didn't)
what am i missing? I am also using chirpy if there is something that it can do to help...
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
T4MvcJs 将帮助您处理这种情况。
它会生成一个 .js 文件,您可以在外部 js 脚本中使用该文件。
使用它很像 T4Mvc:MvcActions.User.Index() 将为您提供“/user/index”。
T4MvcJs will help you handle that case.
It generates a .js file which you can use in your external js-scripts.
Using it is a lot like T4Mvc: MvcActions.User.Index() will give you "/user/index".
与 T4MVC 相比,这更像是一个常见的 MVC 问题。 T4MVC 简化了调用 @Url.Action 的方式,但无论您是否使用 T4MVC,您都无法在纯 .js 文件中包含服务器代码。
但是,有一些解决方案,例如 使用内联 C# MVC 框架中的 Javascript 文件内
This is more of a general MVC question than T4MVC. T4MVC simplifies how you call @Url.Action, but whether you use T4MVC or not, you won't be able to have server code in a plain .js file.
However, there are some solutions around, like Using Inline C# inside Javascript File in MVC Framework