Question

In c# I have one method

public IEnumerable<Office> PointOffices;

private void PrepareMap(IEnumerable<Office> tdMaps)
  {
      var pointOffices = tdMaps as Office[] ?? tdMaps.ToArray();
      if (tdMaps == null || !pointOffices.Any()) return;
      PointOffices = pointOffices;
 }

In JavaScript I want to get each element of Office and generate different html with attributes of Office class

I tried to do like this

var pointOffices =<%= PointOffices %>;

but it gives me error: Unexpected token ]

Do I need to serialise the class or the method to get it in js ? how can I realize this?

Was it helpful?

Solution

Do I need to serialise the class or the method to get it in js?

Yep!

Check out JSON.NET.

So in your example you should be able to do something like this

public string SerializedPointOffices
{
    get { return JsonConvert.SerializeObject(this.PointOffices); }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top