This is the first time I am working with json. I am trying to return Json from my action method:
public JsonResult Upload() { ... return Json(new { foo = "sos....sos....sos..."}); }
But as a result, all I get is my message wrapping in this "pre" tag. How to parse "foo" from this?
"<pre style="word-wrap: break-word; white-space: pre-wrap;">{"foo":"sos....sos....sos..."}</pre>"
I think the reason you get the data enclosed in the pre-tag is because you are requesting the data as HTML, not plain text or json.
Try specifying the data type as json to stop the conversion of the response to HTML.
This returns the contents of the first pre-tag with the class "yourclass".
document.querySelector("pre.yourclass").innerHTML
Perhaps the client-side handler is trying to verify that the server response is well-formed HTML. I believe that some javascript libraries with support for file uploads will not cover the HTML tags in the tag that you are describing. A very unintuitive solution might be to set the mimetype type on the server as "text / html", so the ajax handler does not try to wrap the response.