T4MVC 与外部 javascript 文件一起使用

发布于 2024-12-13 08:04:07 字数 251 浏览 3 评论 0原文

是否可以在外部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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏至、离别 2024-12-20 08:04:07

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".

谎言 2024-12-20 08:04:07

与 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文