开发者

JavaScript parameter between <%%>

I have a 'demo' controller with 'demo' action that gets a parameter, and I want to give them in JavaScript.

aspx:

<script type="text/javascript">
function openDefault(miez) {
       var manager1 = $find("<%= RadWindowManag开发者_Go百科er2.ClientID %>");
       var str = "/demo/demo/" + miez;
       manager1.open(str3, "RadWindow2");
}  
</script>

It works if I give them one parameter, but for example miez="par1 par2", it doesn't works. (of course, because /demo/demo/park1 par2 address doesn't exists).

So I tried another way:

aspx:

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

This works without parameters. The problem is that I don't know how can I give parameter using this form, if the parameter is a JavaScript variable.

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

How can I get 'par1' to replace the value of 'miez'?


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


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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜