我正在尝试使用参数将数据从视图传递到控制器。
现在我遇到了一些困难。一旦我从表中选择一行并按下具有 ShowTasks() 的 onclick 方法的按钮,我就尝试传递这些参数
C# 控制器:
[Route("/service/delivery/{id}/{shopdoccode}/{regdate}")]
public ActionResult Delivery(string id, string shopdoccode, string regdate)
{
//do stuf
}
用户点击按钮时的Javascript函数:
function ShowTasks() {
//Dear Stackoverflow > This works, this is for selecting a row in the table
var $selectedRow = $(".highlight");
if ($selectedRow.length == 1) {
var dcColumn = 0;
var rdColumn = 1;
var shopdoccodeColumn = 3;
//assigning name to the colomn value
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
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("Succes");
}
},
error: function (data) {
console.log("Error");
}
});
}
}
}
到目前为止我做了什么?我花了几个小时试图找到一种方法来将参数提供给我的控制器,以便我可以调用 SQL 存储过程。
不幸的是,我不能简单地使用隐藏表单来实现这一点。
这也很有帮助:Url.Action 参数? https://stackoverflow.com/questions/6278694/url-action-parameters
@sleeyuen