Skip to main content
added 53 characters in body
Source Link
EndangeredMassa
  • 17.5k
  • 8
  • 57
  • 81

You have to do a bit more work to get the data into a form that JavaScript can understand. The easiest way is to encode the data in the object as a JSON string, then emit that to the data variable instead.

You can do this manually (by creating a method of the class that does this) or since you are using ASP.NET MVC you can use the Json method. However, this will have to be done in the Controller instead of the View. So, I would add it to your Model object or in the generic View Data. It can probably exist as a property of the Model object that just calls the Json method on the original value and returns it.

C#

public string JsonPayHistory { get { return Json(PayHistory); } } 

JS

var data = '<%= Model.JsonPayHistory %>'; 

You will want to take a look at the string that is returned. It will be in the JSON format and will have to be evaluated. You can do this by adding:

data = eval(data); // usually a bad idea 

This uses the eval function to build the JavaScript object.or

data = JSON.parse(data); // may require a library if browser doesn't support it 

Now, you should have an object that is similar to your C# object. You can loop over it and reference properties by name. If you provide the basic structure of your PayHistory object, I can give better examples.

You have to do a bit more work to get the data into a form that JavaScript can understand. The easiest way is to encode the data in the object as a JSON string, then emit that to the data variable instead.

You can do this manually (by creating a method of the class that does this) or since you are using ASP.NET MVC you can use the Json method. However, this will have to be done in the Controller instead of the View. So, I would add it to your Model object or in the generic View Data. It can probably exist as a property of the Model object that just calls the Json method on the original value and returns it.

C#

public string JsonPayHistory { get { return Json(PayHistory); } } 

JS

var data = '<%= Model.JsonPayHistory %>'; 

You will want to take a look at the string that is returned. It will be in the JSON format and will have to be evaluated. You can do this by adding:

data = eval(data); 

This uses the eval function to build the JavaScript object. Now, you should have an object that is similar to your C# object. You can loop over it and reference properties by name. If you provide the basic structure of your PayHistory object, I can give better examples.

You have to do a bit more work to get the data into a form that JavaScript can understand. The easiest way is to encode the data in the object as a JSON string, then emit that to the data variable instead.

You can do this manually (by creating a method of the class that does this) or since you are using ASP.NET MVC you can use the Json method. However, this will have to be done in the Controller instead of the View. So, I would add it to your Model object or in the generic View Data. It can probably exist as a property of the Model object that just calls the Json method on the original value and returns it.

C#

public string JsonPayHistory { get { return Json(PayHistory); } } 

JS

var data = '<%= Model.JsonPayHistory %>'; 

You will want to take a look at the string that is returned. It will be in the JSON format and will have to be evaluated. You can do this by adding:

data = eval(data); // usually a bad idea 

or

data = JSON.parse(data); // may require a library if browser doesn't support it 

Now, you should have an object that is similar to your C# object. You can loop over it and reference properties by name. If you provide the basic structure of your PayHistory object, I can give better examples.

added 236 characters in body; added 144 characters in body
Source Link
EndangeredMassa
  • 17.5k
  • 8
  • 57
  • 81

You have to do a bit more work to get the data into a form that JavaScript can understand. The easiest way is to encode the data in the object as a JSON string, then emit that to the data variable instead.

You can do this manually (by creating a method of the class that does this) or since you are using ASP.NET MVC you can use the Json method. However, this will have to be done in the Controller instead of the View. So, I would tryadd it to your Model object or in the followinggeneric View Data. It can probably exist as a property of the Model object that just calls the Json method on the original value and returns it.

C#

public string JsonPayHistory { get { return Json(PayHistory); } } 

JS

var data = '<%= Json(Model.PayHistory)JsonPayHistory %>'; 

You will want to take a look at the string that is returned. It will be in the JSON format and will have to be evaluated. You can do this by adding:

data = eval(data); 

This uses the eval function to build the JavaScript object. Now, you should have an object that is similar to your C# object. You can loop over it and reference properties by name. If you provide the basic structure of your PayHistory object, I can give better examples.

You have to do a bit more work to get the data into a form that JavaScript can understand. The easiest way is to encode the data in the object as a JSON string, then emit that to the data variable instead.

You can do this manually (by creating a method of the class that does this) or since you are using ASP.NET MVC you can use the Json method. So, I would try the following.

var data = '<%= Json(Model.PayHistory) %>'; 

You will want to take a look at the string that is returned. It will be in the JSON format and will have to be evaluated. You can do this by adding:

data = eval(data); 

This uses the eval function to build the JavaScript object. Now, you should have an object that is similar to your C# object. You can loop over it and reference properties by name. If you provide the basic structure of your PayHistory object, I can give better examples.

You have to do a bit more work to get the data into a form that JavaScript can understand. The easiest way is to encode the data in the object as a JSON string, then emit that to the data variable instead.

You can do this manually (by creating a method of the class that does this) or since you are using ASP.NET MVC you can use the Json method. However, this will have to be done in the Controller instead of the View. So, I would add it to your Model object or in the generic View Data. It can probably exist as a property of the Model object that just calls the Json method on the original value and returns it.

C#

public string JsonPayHistory { get { return Json(PayHistory); } } 

JS

var data = '<%= Model.JsonPayHistory %>'; 

You will want to take a look at the string that is returned. It will be in the JSON format and will have to be evaluated. You can do this by adding:

data = eval(data); 

This uses the eval function to build the JavaScript object. Now, you should have an object that is similar to your C# object. You can loop over it and reference properties by name. If you provide the basic structure of your PayHistory object, I can give better examples.

Source Link
EndangeredMassa
  • 17.5k
  • 8
  • 57
  • 81

You have to do a bit more work to get the data into a form that JavaScript can understand. The easiest way is to encode the data in the object as a JSON string, then emit that to the data variable instead.

You can do this manually (by creating a method of the class that does this) or since you are using ASP.NET MVC you can use the Json method. So, I would try the following.

var data = '<%= Json(Model.PayHistory) %>'; 

You will want to take a look at the string that is returned. It will be in the JSON format and will have to be evaluated. You can do this by adding:

data = eval(data); 

This uses the eval function to build the JavaScript object. Now, you should have an object that is similar to your C# object. You can loop over it and reference properties by name. If you provide the basic structure of your PayHistory object, I can give better examples.