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

216
Vistas
send data to method in controller by javascript @Url.Action

Hi i try send data to method in controller

 var data = {
  Id: e.row.key.Id
 }
       
 window.location.href = '@Url.Action("Show", "Calculations", new {param1 =  data})';
  //here in javascript I have error, near 'data'

error

the name 'data' does not exist in current context

Controller

[HttpGet]
    public async Task<ActionResult> Show(string data)

I tried

     window.location.href = '@Url.Action("Show", "Calculations")' +"/"+ data;  

but in method in Show(string data) i have null value in 'data'

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Assuming you'd be able to change to route to accept the id in the route {controller}/{action}/{id}, you could just send the id directly, as follows:

 window.location.href = '@Url.Action("Show", "Calculations")/' + e.row.key.Id; 

and

[HttpGet]
    public async Task<ActionResult> Show(Guid Id)
about 4 years ago · Juan Pablo Isaza Denunciar

0

For default route

window.location.href = '@Url.Action("Show", "Calculations")' +"?data="+ data;

If you are using custom maproute you need an attribute for route. Like this;

[HttpGet]
[Route("Show/{Id}")]
public async Task<ActionResult> Show(Guid Id)

You can check this https://docs.microsoft.com/tr-tr/aspnet/core/mvc/controllers/routing?view=aspnetcore-6.0

about 4 years ago · Juan Pablo Isaza Denunciar

0

As you have parameter name = data at controller level, try below

var dataObj = {
  Id: e.row.key.Id
 }
       
 window.location.href = '@Url.Action("Show", "Calculations", new {data = dataObj})';

You were missing parameter name in Url.Action. this name has to match as is at both controller and in script file.
about 4 years ago · Juan Pablo Isaza 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