1

I have a basic app service that creates a title. When my clientside page passes the parameter values to my server side function with special characters, question marks are appearing.

May I ask how do I fix this?

My current code.

index.js

var title = "Búsq"
titleService.CreateTitle(title).success(function (data) {
    vm.title= data;
});

TitleAppService.cs

public string CreateTitle(string title)
{
    // title is received here as B�sq <- how do I resolve this, it should be Búsq
}
Phoenix
  • 467
  • 4
  • 18
  • Is there a chance that the `title` parameter is passes in the entry path (as a `query string` parameter)? Because if so - it should be encoded first – ymz Jan 14 '19 at 17:29
  • @ymz any tips on encoding it would be greatly appreciated – Phoenix Jan 14 '19 at 17:39
  • How did you store index.js on the disk? Try to store index.js using utf-8 encoding – NineBerry Jan 14 '19 at 17:41

1 Answers1

0

Assuming the title parameters is passed as a part of the url it should be encoded BEFORE sending to the server. In some platforms the value should be decoded on server-side

Client-Side encoding - JS (From MDN)

titleService.CreateTitle(encodeURIComponent(title)).success(function (data) {
    vm.title= data;
});

Server-Side decoding - C# (Follow this answer)

public string CreateTitle(string title)
{
    title = Server.UrlDecode(title);
}
ymz
  • 6,602
  • 1
  • 20
  • 39