开发者

c# const in jQuery?

I have this piece of code in javascript:

 var catId = $.getURLParam("category");

In my asp.net and c# code for "category" query string i use a public const:

public const string CATEGORY = "category";

so if i want to change the query string parameter to be "categoryTest" i o开发者_如何学运维nly change this const and all the code is updated.

Now the question is: how can i do something similar for the javascript i have in the same application (so i want to use the same constant)?

I mean i want something like this:

var catId = $.getURLParam(CQueryStringParameters.CATEGORY);

but because there are none asp.net tags, my const is not interpreted...

Any workaround?


Declare a global variable in your aspx page:

<script type="text/javascript">
var categoryParam = '<%= CQueryStringParameters.CATEGORY %>';
</script>

And then use this global variable in your javascript file:

var catId = $.getURLParam(categoryParam);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜