0

I have a separate javascript file (*.js) that is included in my asp.net mvc4 view. In that js file I am using razor notation to get the path of an image like this:

@Url.Content("~/images/MyImages.gif")

but it is not working so how to obtain the correct path poiting to the image from js file if razor cannot be used?

1 Answer 1

1

It is not possible to use Razor in a javascript file (you can use it in the Javascript you place in your view).

Option 1: You can pass the image path as a parameter to the javascript function.

Option 2: Create an action method that returns a JSON object with a list of Image paths. This action should be called one time and stored in your Javascript code. Then you can access that list, doing a lookup for some id.

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

Comments

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.