c# - How to register a List in JS and iterate it? -


I have written some code in ASP.net: the back code:

  public string location { get; Set; } Public listing & lt; String & gt; Categories {Get; Set; } Public listing & lt; String & gt; Hrefs {Get; Set; } Public String Categories J {get; Set; } Public string HrefsJ {get; Set; } ... this.CategoriesJ = new JavaScriptSerializer (). Serialize (Categories); this. HrefsJ = New JavaScript Serializer (). Serialize (categories); JS in markup:  
  & lt; Script type = "text / javascript" src = "scripts / jquery-1.4.1.js" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; Var Categories = jQuery.parseJSON (this.CategoriesJ); Hrefs = jQuery.parseJSON (this.HrefsJ); Function onInit () {Warning (Categories [0]); }; & Lt; / Script & gt;   

Is it OK to use Index such as Jason Worl? Is this the right way to write?

So why do not I look alert? The code behind the Var is equal to: ["Restaurants", "Restaurants"] I get an error: Uncustom Type Error: Property '0' can not be read blank

You can not reference server-side variables in such ASPX. You need it in ASP.NET:

  & lt; Script type = "text / javascript" src = "scripts / jquery-1.4.1.js" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; Var Categories = & lt;% = CategoriesJ% & gt; Var Hrefs = & lt;% = HrefsJ% & gt;; Function onInit () {Warning (Categories [0]); }; & Lt; / Script & gt;    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -