0

I have MVC2 applications that runs well on the root of website, however when I publish it to a Virtual Directory, none of the images or css worked. I used Url.Content, and all worked except for video files using Javascript and JW Player. I am building my dynamic buttons using:

onClick = string.Format("videoplayer('../video/{0}')", VideoName);

Now I need to use Url.Content, tried several ways but failed, I would appreciate your input. Thanks in advance

1 Answer 1

2

You could separate your markup and javascript. For example you could use HTML5 data-* attributes and jQuery:

<div class="player" data-url="<%= Url.Content("~/video") %>/foo.avi">
    Play foo
</div>

<div class="player" data-url="<%= Url.Content("~/video") %>/bar.avi">
    Play bar
</div>

and then in a separate javascript file you could subscribe to the .click event:

$(function() {
    $('.player').click(function() {
        var url = $(this).data('url');
        videoplayer(url);      
        return false;
    });
});
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Darin, your solution works well; however I would like to place '<%= Url.Content("~/video/" + VideoName) %>' in my existing fuction(videoname){ var videotoplay = '<%= Url.Content("~" + videoname) %>'; I get the videoname from my button as /video/test.mp4. I am getting error The name 'videoname' does not exist in the current context. Thanks
@user373721, ah, so videoname is a javascript variable? You should have explained that in your question. I will update my answer with an example.
Darin is correct but you also need to learn some debugging skills. Use Fiddler/F12 tools and even view source to figure out the requested URL and why it's not working.

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.