1

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

KanTube
  • 61
  • 1
  • 3

2 Answers2

3

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

Shaddix
  • 5,901
  • 8
  • 45
  • 86
0

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

Community
  • 1
  • 1
David Ebbo
  • 42,443
  • 8
  • 103
  • 117
  • Thanks for the reply, I will wait for you/MS to come up with a solution in the future... also T4MVC is very nice and should be part of VS in the next release as well as the chirpy functionality to compile/compress .less/.css/.js files. – KanTube Nov 02 '11 at 17:10