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

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.