In MVC I can do something like the following to serialise an object with an anonymous type to JSON…
Public Function GetStateList() As JsonResult
Dim MyObject = New With {.Id = 1, .Property = "SomeValue"}
Return Me.Json(MyObject)
End Function
which would return something like;
{
"Id": 1,
"Property"SomeValue",
}
I’d like to do exactly the same but output xml. I haven’t been able to find an equivalent method. Would someone please point me in the right direction?
Many thanks
As per James’ answer there is no native way of doing this. Using Reflector, I examined the
System.Web.MVC.dlland and found out how MVC does it. The core of the code is below.It’s fairly self-explanatory and was easy enough to convert.