简体   繁体   中英

Accessing JS variable in Razor and Aspx

This is my code:

<% if (someCondition) { %>

    var activeTab = $("#myTabs").tabs("option", "active");
    var language = <% myLanguages[activeTab] %> ;

<% } %>

myLanguages is of type Dictionary.

I want to access myLanguages[activeTab]. How do I do this?

Try this, this variable gets the value of the variable, at render time :

<% if (someCondition) { %>

    var activeTab = $("#kioskTabs").tabs("option", "active");
    var language = '@Html.Raw(myLanguages[activeKioskTab])';

<% } %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM