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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:24:32+00:00 2026-05-31T22:24:32+00:00

I have a form on a webpage that I submit using the jquery form

  • 0

I have a form on a webpage that I submit using the jquery form plugin. This form includes a file upload option. The MVC3 action that I post to returns JSON. Since the plugin falls back to using an iframe on older browsers you need to wrap your JSON with a

<textarea>JSON data...</textarea>

I tried changing the return type of the action to string and just appending the text area tags the the JSON object.ToString() but no go. How can I wrap my JSON result in a textarea when !Request.IsAjaxRequest()

Here is an example of me just trying to return the JSON as a string (which doesn’t work)

[HttpPost]
    public string CreateEntry(EntryCreateViewModel model)
    {
        if (!ModelState.IsValid)
        {
            return WrapInTextArea(!Request.IsAjaxRequest(), Json(new object[] { false, 0, this.RenderPartialViewToString("_EntryCreateFormPartial", model) }).ToString());
        }

This works in modern browsers but I suspect (based on the docs) will fail in older browsers that use an iframe

[HttpPost]
    public ActionResult CreateEntry(EntryCreateViewModel model)
    {
        if (!ModelState.IsValid)
        {
            return Json(new object[] {false, 0, this.RenderPartialViewToString("_EntryCreateFormPartial", model)});
        }
  • 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-31T22:24:33+00:00Added an answer on May 31, 2026 at 10:24 pm

    To solve this I inherited from JsonResult and added the textarea there

    using System;
    using System.Web.Mvc;
    using System.Web.Script.Serialization;
    
    namespace TinyHouseMap.Web.Infrastructure.Results
    {
        public class JsonInIframeResult : JsonResult
        {
            public bool EncloseInTextArea
            {
                get;
                set;
            }
    
            public override void ExecuteResult(ControllerContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException("context");
                }
    
                if ((JsonRequestBehavior == JsonRequestBehavior.DenyGet)
                    && string.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException("JsonRequest GetNotAllowed");
                }
    
                var response = context.HttpContext.Response;
    
                response.ContentType = !string.IsNullOrEmpty(ContentType) ? ContentType : "application/json";
    
                if (ContentEncoding != null)
                {
                    response.ContentEncoding = ContentEncoding;
                }
    
                if (Data != null)
                {
                    var serializer = new JavaScriptSerializer();
    
                    string results;
                    if (EncloseInTextArea)
                    {
                        results = "<textarea>" + serializer.Serialize(Data) + "</textarea>";
                    }
                    else
                    {
                        results = serializer.Serialize(Data);
                    }
    
    
                    response.Write(results);
                }
            }
        }
    }
    

    And then created a helper in my controller base class

    protected JsonInIframeResult JsonInIframe(object data, string contentType, bool encloseInTextArea)
        {
            var result = new JsonInIframeResult {Data = data, ContentType = contentType, EncloseInTextArea = encloseInTextArea};
            return result;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have form action file in another directory but some file send to this
I have a mobile webpage that is just a simple form with a submit
I'm using django, and have a static webpage with a GET form, and about
I have a login form using jquery ajax and a php code. The issue
I have a webpage that is using Google's custom search engine. I wanted to
I have a webpage that looks like: <html> <head> <title>Hi</title> </head> <body> <form name=mainForm
I have a method toggleDrawer(this) That expands a small window component on my webpage.
I have a webpage with search form fields and on click of submit button,
I have a webpage that contains a form, and i need to refresh the
I have a few asp:textbox controls in a form on a webpage, below is

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.