Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

442
Visualizações
Passing params through URL - Single quotes become '

I'm working with a ASP.NET project. We are passing params through the url and every time a single quote is passed the url changes all single quotes to %27 and the actual value read in through the javascript changes all single quotes to '

Can someone tell me how I can maintain the single quotes as our parameters need to match the exact values. This is my code.

public class Model
{
   public string example {get; set;}
}

public ActionResult Index(string example)
{
   var model = new Model();
   model.example = example;
   return View(model);
}

Index.cshtml at the bottom ---------------------

<script type="text/javascript">
   var example = "@Model.example";
   Main();
</script>

Javascript -----------------

console.log(example);

Examples: www.example.com?example=Turtle's_Are_Cool Changes the url instantly to => www.example.com?example=Turtle\%27s_Are_Cool and the JavaScript outputs Turtle&#39s_Are_Cool

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you want to do it on the server side you can use Server.URLEncode("Turtle's_Are_Cool"))

If you want to manage the same on client-side you can replace ' with '

example = example.replace(/'/g, "\'");

But if you have got a single quote coming from server-side and you want to convert it at client-side then the easiest way is to use HTML element as shown in the below question

Unescape apostrophe (&#39;) in JavaScript?

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda