Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

428
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda