문제

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