hncl
hncl

Reputation: 2295

MVC2 - IIS7, Virtual Directory - Url.Content

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

Upvotes: 0

Views: 522

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

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;
    });
});

Upvotes: 2

Related Questions