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 4344216
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:51:54+00:00 2026-05-21T11:51:54+00:00

i have the following code in c#. I’m using ASP.NET MVC 3. public override

  • 0

i have the following code in c#. I’m using ASP.NET MVC 3.

public override void ExecuteResult(ControllerContext context)
{

    // If ContentType is not expected to be application/json, then return XML
    if ((context.HttpContext.Request.ContentType ?? String.Empty).Contains("application/json"))
    {
        new JsonResult { Data = this.Data }
            .ExecuteResult(context);
    }
    else
    {
        using (MemoryStream stream = new MemoryStream(500))
        {
            using (var xmlWriter = XmlTextWriter.Create(
                stream,
                new XmlWriterSettings()
                {
                    OmitXmlDeclaration = true,
                    Encoding = UTF8,
                    Indent = true
                }))
            {
                new XmlSerializer(typeof(T), IncludedTypes)
                    .Serialize(xmlWriter, this.Data);
            }
            // NOTE: We need to cache XmlSerializer for specific type. Probably use the 
            // GenerateSerializer to generate compiled custom made serializer for specific
            // types and then cache the reference
            new ContentResult
            {
                ContentType = "text/xml",
                Content = UTF8.GetString(stream.ToArray()),
                ContentEncoding = UTF8
            }
                .ExecuteResult(context);
        }
    }
}

I’m trying to return a json or a xml result depending the request. The problem is that i get context.HttpContext.Request.ContentType = "" when i run it.

Is there a way to make the application know that the request is “application/json”?

I’m returning this result object in a controller method called GetGoogleMapsMarkers:

 $(document).ready(function () {
    $.ajax({
        type: "POST",
        url: "http://localhost:1939/API/Google/GetGoogleMapsMarkers",
        datatype: "json",
        contentType: "application/json; charset=utf-8",
        success: function (data) {

            alert(data);

        }
    }
});

Help me please.
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-21T11:51:55+00:00Added an answer on May 21, 2026 at 11:51 am

    i added

    data: { },

    to the ajax call and it worked…. it’s weird but it made it work…

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

Sidebar

Related Questions

I have following code: [TestMethod] public void StartWorkInFirstThread() { if (SynchronizationContext.Current == null) SynchronizationContext.SetSynchronizationContext(
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
i have following code for allocation two dimensional array #include <iostream> using namespace std;
i have following code #include <iostream> #include <string> using namespace std; string generate(){ for
I have following code that is accepting a form submission [ActionName(TestingTemp), AcceptVerbs(HttpVerbs.Post)] public ActionResult
i have following code #include <iostream> #include <set> #include <string> using namespace std; template<class
I have following code <asp:SqlDataSource ID=SqlDataSource1 runat=server UpdateCommand=UPDATE [gMeter] SET ... [userId] = @userId
I have following code class Test { public: int &ref; int a; Test(int &x)
I have following code to accomplish prefix sum task: #include <iostream> #include<math.h> using namespace
I have following code for 3 DataGridView Controls in my VB.NET winform application. How

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.