0
我有以下代碼...傳遞 「數據 - 」 到控制器
HTML:
<button type="button" class="btn btn-primary" id="filterData"
data-filterString="@Model.LastName">Filter</button>
打字稿:
$("button[id='filterData']").click(() => {
var dataList = [];
var filter = $(this).data("filterString");
$("input[class='personRecord']").each(function() {
dataList.push($(this).val());
});
var parameters = JSON.stringify({ "filterString": filter, "dataList":paymentList });
$.ajax({
url: "/Employee/FilterName",
data: parameters,
type: "POST",
contentType: "application/json; charset=utf-8",
success: function() {
alert("Success");
}
});
});
控制器:
[HttpPost]
public void SendAll(string filterString, List<string> dataList) {
...
}
然而,變量filter
不斷返回「未定義」。在這種情況下,你如何傳遞自定義數據項,data-filterString
?
檢查HTML您的生成 - 它是'數據filterString = 「... 」'或'數據filterstring =「 ...」'(全部小寫)? –