为什么不能在 ajax 中使用 beginform?



我需要发送id我的加载页面,如何发送id并加载另一个页面?

MY 错误:未捕获语法错误:意外字符串 我现在这个错误语法错误,但 ı 尝试了一切,ı 是 ajax 和 mvc 中的新手

这是我的代码:

$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url : "http://localhost:9000/api/Customer/CustomerList",
success: function (data) {
$("#customerList").DataTable({
pageLength:50,
destroy: true,
"data": data,
"columns": [
{ "data": "CustID"},
{
"data":   function send(data) {
return "@using (Html.BeginForm("CustomerList", "Customers", FormMethod.Post, new { target = "_blank" })) {<input type='submit' value=" + data.custID + " />}";
}
}
]
});
},
error: function (data) {
alert("CustomerList");
}
});

Razor 语法必须先解析,然后才能工作。如果您检查页面的输出,您将永远不会找到"Html.BeginForm"标签/代码。

您的代码显示您正在使用 ajax 请求获取客户列表。您可以简单地使用相同的技术在单击按钮时发布 id。

return "<input type='submit' onClick='sendID(" + data.custID )'/>";

sendID 函数可能看起来像这样

函数发送ID(客户ID({

$.ajax({
type: "POST",
data: {custID: customerID},
contentType: "application/json; charset=utf-8",
url : "http://localhost:9000/api/Customer/GetCustomer", // your endpoint url here
success: function (data) {
// do something
});
},
error: function (data) {
alert("Could not send customerid");
}
});

}

这是未经测试的代码。

最新更新