What is the correct way for getting JavaScript Intellisense in Visual Studio 2010 when creating a client side object with the JavaScriptSerializer
?
For example, I have a class named Record
with several properties; I'm generating a collection of Records
and then serializing them using the JavaScriptSerializer
.
Code Behind
public string JsonRecords
{
get
{
var js = new System.Web.Script.Serialization.JavaScriptSerializer();
return js.Serialize( Records );
}
}
ASPX page
<script>
// mocks the Record object
var records = [{ "Date": "", "Latitude": 0, "Longitude": 0 }];
// sets the Record object
records = <%= JsonRecords %>;
</script>
When I pre-fill the JS records variable to mock the Records
class, I get complete intellisense support with Visual Studio.
This works, but it feels dirty. Is there a more appropriate method? Or is this a common practice?