Convert C# Model To Plain Json-string
Is there any simple way to convert an C#-object into a plain string that is escaped and can be used by javascript? I try to pass the string into a jQuery-function which will replac
Solution 1:
Just get rid of the double quotes.
Make sure this is added in the script tag of your view.
varjsVariable=@Html.Raw(Json.Encode(newMyClass()))
you'd then get a javascript object with its properties - provided MyClass
is defined, and is accessible in your CSHTML.
jsVariable.myProp, jsVariable.myOtherProp
. . etc
Post a Comment for "Convert C# Model To Plain Json-string"