My ViewModel have a baseview model and one member, let's call it "Data" of type of string and I get this data I get by deserializing a complex xml file in my controller)
When debugging in VS and viewing the value of the deserialized xml file as text, it looks perfect, just what I want.
But now my action method have to send it back in the view model above (I need the base view model properties, therefore have derived type and added the "Data" member to hold the jsonl)
However, when I get the result back in a browser (testing) the Data member are all weird, full of slashes and stuff.
So I guess I should not be using a string as data type for member, rigth? Or what?
Better get this right because the client app is a mobile app that expect the data in json.
krokonoster
Contributor
4291 Points
1352 Posts
How to correctly return json as member of view model to calling client
Dec 16, 2012 07:15 PM|LINK
Hi,
My ViewModel have a baseview model and one member, let's call it "Data" of type of string and I get this data I get by deserializing a complex xml file in my controller)
When debugging in VS and viewing the value of the deserialized xml file as text, it looks perfect, just what I want.
But now my action method have to send it back in the view model above (I need the base view model properties, therefore have derived type and added the "Data" member to hold the jsonl)
However, when I get the result back in a browser (testing) the Data member are all weird, full of slashes and stuff.
So I guess I should not be using a string as data type for member, rigth? Or what?
Better get this right because the client app is a mobile app that expect the data in json.
kevinstone
Member
236 Points
48 Posts
Re: How to correctly return json as member of view model to calling client
Dec 18, 2012 10:43 PM|LINK
have you tried:
System.Web.Helpers.Json.Encode(object value)?