0

Actually i have created one page with text and image saving process to database. So i have used form-data. Everything is fine but when we give text with spaces, the spaces changed to '+' symbol. Please find below code for how i tried,

Script :

var fileData = new FormData();
var notes = "testing testing testing testing testing testing testing te";
fileData.append('notes', notes);
 $.ajax({
                url: "api/update",
                type: "POST",
                data: fileData,
                },
                success: function (response) {
                    alert("saved");
                }
});

I can get same string while debug Script. But after we posted from script to Action only i can get string as "testing+testing+testing+testing+testing+testing+testing+test".

C# :

[HttpPost]
[Route("api/update")]
public async Task<dynamic> PostAsyncOccupantImage()
{
      string error = string.Empty;
      MyStreamProvider streamProvider = new MyStreamProvider();
      await Request.Content.ReadAsMultipartAsync(streamProvider);
      var notes = streamProvider.FormData.ToString().Split('&')[0]
      return error;
}

Please give your suggestion. Thanks, Arun D

3
  • stackoverflow.com/a/11447443/5233656 you can refer from here Commented Oct 6, 2017 at 9:47
  • We have no idea what the heck MyStreamProvider is or where it gets its data or what it does with that data. Commented Oct 6, 2017 at 9:54
  • No, instead of your given link i can replace '+' as ' ' in Method. I need to know why its happen and how its resolve @Mark Commented Oct 6, 2017 at 9:56

1 Answer 1

1

It is explained in the answer of the link that Mark gave:

In some GET and POST requests (most likely in the URL, or via a form), spaces are encoded as "+" (plus) symbols before they are passed to the server.

This is because URLs cannot contain spaces.

Note: this only goes for application/x-www-form-urlencoded content. The space character is otherwise encoded to this: %20.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.