Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3240576
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:06:04+00:00 2026-05-17T18:06:04+00:00

In MVC I can do something like the following to serialise an object with

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:06:05+00:00Added an answer on May 17, 2026 at 6:06 pm

    As per James’ answer there is no native way of doing this. Using Reflector, I examined the System.Web.MVC.dll and and found out how MVC does it. The core of the code is below.

    Private Sub SerializeCustomObject(ByVal o As Object, ByVal sb As StringBuilder, ByVal depth As Integer, ByVal objectsInUse As Hashtable, ByVal serializationFormat As SerializationFormat)
        Dim flag As Boolean = True
        Dim type As Type = o.GetType
        sb.Append("{"c)
        If (Not Me.TypeResolver Is Nothing) Then
            Dim str As String = Me.TypeResolver.ResolveTypeId(type)
            If (Not str Is Nothing) Then
                JavaScriptSerializer.SerializeString("__type", sb)
                sb.Append(":"c)
                Me.SerializeValue(str, sb, depth, objectsInUse, serializationFormat)
                flag = False
            End If
        End If
        Dim info As FieldInfo
        For Each info In type.GetFields((BindingFlags.Public Or BindingFlags.Instance))
            If Not info.IsDefined(GetType(ScriptIgnoreAttribute), True) Then
                If Not flag Then
                    sb.Append(","c)
                End If
                JavaScriptSerializer.SerializeString(info.Name, sb)
                sb.Append(":"c)
                Me.SerializeValue(info.GetValue(o), sb, depth, objectsInUse, serializationFormat)
                flag = False
            End If
        Next
        Dim info2 As PropertyInfo
        For Each info2 In type.GetProperties((BindingFlags.GetProperty Or (BindingFlags.Public Or BindingFlags.Instance)))
            If Not info2.IsDefined(GetType(ScriptIgnoreAttribute), True) Then
                Dim getMethod As MethodInfo = info2.GetGetMethod
                If ((Not getMethod Is Nothing) AndAlso (getMethod.GetParameters.Length <= 0)) Then
                    If Not flag Then
                        sb.Append(","c)
                    End If
                    JavaScriptSerializer.SerializeString(info2.Name, sb)
                    sb.Append(":"c)
                    Me.SerializeValue(getMethod.Invoke(o, Nothing), sb, depth, objectsInUse, serializationFormat)
                    flag = False
                End If
            End If
        Next
        sb.Append("}"c)
    End Sub
    

    It’s fairly self-explanatory and was easy enough to convert.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I write the following in MVC? <input type=text name=ProjectList[' + count++ +
In ASP.NET MVC view helper, you can do something like <%= Html.ActionLink(click me, DoSomething,
Is it possible to do something like this in an ASP.NET MVC controller? public
I'm learning asp.net mvc and found something interesting: It seems that I can't explicitly
I'm wondering if the following may be possible using something like jQuery. I've looked
I need to do something like the following: On the page, when a checkbox
In my Node/Express.js project I can set the views folder globally like so: app.configure(function()
So I wanted to do something like this: @Component @Scope(value=request, proxyMode=ScopedProxyMode.INTERFACES) public class MyBean
just wondering if there is something built into asp.net mvc where I can override
Hi, The login method in my ASP.NET MVC page looks something like this :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.