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

215
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 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