Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
enviar datos al método en el controlador por javascript @ Url.Action

Hola, intento enviar datos al método en el controlador.

 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

el nombre 'datos' no existe en el contexto actual

Controlador

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

Lo intenté

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

pero en el método en Mostrar (datos de cadena) tengo un valor nulo en 'datos'

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Suponiendo que pueda cambiar a la ruta para aceptar la identificación en la ruta {controller}/{action}/{id} , podría enviar la identificación directamente, de la siguiente manera:

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

y

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

0

Para la ruta predeterminada

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

Si está utilizando una ruta de mapa personalizada, necesita un atributo para la ruta. Como esto;

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

Puede consultar esto https://docs.microsoft.com/tr-tr/aspnet/core/mvc/controllers/routing?view=aspnetcore-6.0

about 4 years ago · Juan Pablo Isaza Report

0

Como tiene nombre de parámetro = datos a nivel de controlador, intente a continuación

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!