views:

83

answers:

2

I have jQuery similar to this on a view:

<script>
    $(function() {
        $("#yourID").makeAsyncUploader({
            upload_url: "/Images/AsyncUpload",
            flash_url: '/Scripts/swfupload.swf',
            button_image_url: '/Scripts/blankButton.png'
        });
    });        
</script>

I need to change the upload_url to receive a parameter so that it goes to a Url like:

/Images/AsyncUpload/23

... where 23 is the value of Model.ProjectId.

Is there a way to inject the value I need into the jQuery? I tried ...

upload_url: "/Images/AsyncUpload/<%= Model.ProjectId %>",

... but intellisense was having none of it.

+2  A: 

I believe that the magic is in the single quotes. Note that I like to split it and do string concatenation so that the value stands on its own.

 upload_url: "/Images/AsyncUpload/" + '<%= Model.ProjectId %>',
tvanfosson
also works so +1
Sailing Judo
+1  A: 

Did you try it? Intellisense certainly does hate ASP code blocks inside Javascript, but for me at least, the line you tried would work. The <%= %> tags get rendered before being sent to the client.

JoshJordan
You're right. This does work as-is. I never checked it because intellisense lied to me.
Sailing Judo
Intellisense can be a cruel mistress.
JoshJordan