I am currently facing challenges in passing data from a view to a controller using parameters. My goal is to pass these parameters when I select a row from a table and click on a button that triggers the ShowTasks() function.
Here is the C# controller code snippet:
[Route("/service/delivery/{id}/{shopdoccode}/{regdate}")]
public ActionResult Delivery(string id, string shopdoccode, string regdate)
{
//perform necessary operations
}
Below is the Javascript function triggered by the button click:
function ShowTasks() {
//This section enables selecting a row in the table
var $selectedRow = $(".highlight");
if ($selectedRow.length == 1) {
var dcColumn = 0;
var rdColumn = 1;
var shopdoccodeColumn = 3;
//extracting column values
var id = $selectedRow[0].children[dcColumn].innerText.trim();
var regdate = $selectedRow[0].children[rdColumn].innerText.trim();
var shopdoccode = $selectedRow[0].children[shopdoccodeColumn].innerText.trim();
//ajax call
if (id && regdate && shopdoccode) {
$.ajax({
type: 'POST',
url: '@Url.Action("service", "delivery" ,new { id = "id", shopdoccode = "shopdoccode", regdate = "regdate" })',
data: { id, regdate, shopdoccode },
success: function (data) {
if (data.success) {
console.log("Success");
}
},
error: function (data) {
console.log("Error");
}
});
}
}
}
I have spent hours trying to find a solution for passing parameters to my controller to invoke a SQL stored procedure. Unfortunately, using a hidden form is not an option for me.
In my quest for answers, I found this resource quite helpful: Url.Action parameters?
@sleeyuen https://i.sstatic.net/Nq2S1.png