There are several posts on the Internet that suggest implementing a custom JSON serializer to return JSON from an IEnumerable<T> action in MVC4.
I am 100% sure that I got a very basic ApiController working that was returning JSON *without* any custom serialization. The type in IEnumberable was a ADO.NET Entity Framework class generated from a SQL Server table.
BUT! I did something, and now I am getting this error: The type 'sometype' cannot be serialized to JSON because its IsReference setting is 'True'. The JSON format does not support references because there is no standardized format for representing references. To enable serialization, disable the IsReference
setting on the type or an appropriate parent class of the type.
I had it working before, beyond doubt. All I remember doing is renaming the out of the box Values controller .cs file and refactoring all references to that name. Is there any way I can get back to returning JSON without altering IsReference property
or doing custom JSON formatting?
In the coming RC version(and current source), JSON.NET is the default serializer. I recommend make your application with nightly build dll's.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
. Is there any way to test if my solution is using the dll that using JSON.NET as default serializer?
There may be various way. One simple way is to check whether your web api project have this class avilable System.Net.Http.Formatting.IKeyValueModel
System.Net.Http.Formatting.IKeyValueModel class has been removed from current source.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
greatbear
Member
160 Points
189 Posts
MVC4 IEnumerable JSON
May 21, 2012 01:19 PM|LINK
There are several posts on the Internet that suggest implementing a custom JSON serializer to return JSON from an IEnumerable<T> action in MVC4.
I am 100% sure that I got a very basic ApiController working that was returning JSON *without* any custom serialization. The type in IEnumberable was a ADO.NET Entity Framework class generated from a SQL Server table.
BUT! I did something, and now I am getting this error:
The type 'sometype' cannot be serialized to JSON because its IsReference setting is 'True'. The JSON format does not support references because there is no standardized format for representing references. To enable serialization, disable the IsReference setting on the type or an appropriate parent class of the type.
I had it working before, beyond doubt. All I remember doing is renaming the out of the box Values controller .cs file and refactoring all references to that name. Is there any way I can get back to returning JSON without altering IsReference property or doing custom JSON formatting?
krokonoster
Contributor
4291 Points
1352 Posts
Re: MVC4 IEnumerable JSON
May 23, 2012 12:50 PM|LINK
http://forums.asp.net/t/1772759.aspx/1
greatbear
Member
160 Points
189 Posts
Re: MVC4 IEnumerable JSON
May 23, 2012 03:15 PM|LINK
krokonoster, thanks, but that thread did not help.
krokonoster
Contributor
4291 Points
1352 Posts
Re: MVC4 IEnumerable JSON
May 23, 2012 05:30 PM|LINK
JsonResult? It's in System.Web.Mvc
greatbear
Member
160 Points
189 Posts
Re: MVC4 IEnumerable JSON
May 23, 2012 07:25 PM|LINK
JsonResult IsA ActionResult, not a method. Not sure how they got it working in that thread.
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: MVC4 IEnumerable JSON
May 27, 2012 06:47 AM|LINK
In the coming RC version(and current source), JSON.NET is the default serializer. I recommend make your application with nightly build dll's.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
greatbear
Member
160 Points
189 Posts
Re: MVC4 IEnumerable JSON
May 29, 2012 02:06 PM|LINK
imran, thanks for your post. Is there any way to test if my solution is using the dll that using JSON.NET as default serializer?
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: MVC4 IEnumerable JSON
May 29, 2012 05:45 PM|LINK
There may be various way. One simple way is to check whether your web api project have this class avilable System.Net.Http.Formatting.IKeyValueModel
System.Net.Http.Formatting.IKeyValueModel class has been removed from current source.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
greatbear
Member
160 Points
189 Posts
Re: MVC4 IEnumerable JSON
May 29, 2012 08:52 PM|LINK
Yes, I do have that class, with Keys as a property of IEnumerable<string> type.
So how do I get the current source?
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: MVC4 IEnumerable JSON
May 30, 2012 02:01 AM|LINK
http://blogs.msdn.com/b/henrikn/archive/2012/04/29/using-nightly-nuget-packages-with-asp-net-web-stack.aspx
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD