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

213
Views
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 answers
Answer question

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 Report

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 Report

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