views:

49

answers:

2

Hi

I have a problem.I have a 'demo' controller with 'demo' action what get a parameter, and i want to give them in javascript.

aspx:

<script type="text/javascript">
function openDefault(miez) {
       var manager1 = $find("<%= RadWindowManager2.ClientID %>");
       var str = "/demo/demo/" + miez;
       manager1.open(str3, "RadWindow2");
}  
</script>

it is work's if i give them one parameter, but example miez="par1 par2"; it's doesn't works. (of course, becouse /demo/demo/park1 par2 address doesn't exists). So i tryed another way:

aspx:

<script type="text/javascript">
function openDefault(miez) {
       var manager1 = $find("<%= RadWindowManager2.ClientID %>");
       manager1.open('<% Url.Action("demo", "demo") %>', "RadWindow2");
}  
</script>

And this works without parameters. The problem is that i don't know how can i give parameter this form, if parameters is javacript variable.

manager1.open('<% Url.Action("demo", "demo",new{id="par1"}) %>', "RadWindow2");

The question is, how can i 'par1' to replace onto the value of 'miez'????

Ahead thank you for the help.

+2  A: 

If you need the output of the Url.Action("demo", "demo") server side code, you should place it in a <%=%> section:

manager1.open('<%= Url.Action("demo", "demo",new{id="par1"}) %>', "RadWindow2");
Oded
+1  A: 

First off, try using <%= %> in stead of <% %>

The first will insert the output of the expression into the page, the second will only execute the code and do nothing with the output.

Second thing you need to realize that anything within <% %> is executed at the server. You cannot change what happens in there on the client.

What you probably want to do is generate the url using some sort of placeholder and then replacing the value in javascript.

Something like this:

var baseUrl = '<%= Url.Action("demo", "demo",new{id="par1"}) %>';
var url = baseUrl.replace('par1', 'miez');
Marnix van Valen