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?

有帮助吗?

解决方案

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); }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top