我的班级;
public class Disciplines
{
public int Id { get; set; }
public string Name { get; set; }
}
我的控制员;
public void test (Disciplines discipline)
{
}
并使用ajax我想将参数发送给测试控制器。
我的javascript是;
var disciplines = {Id:1, name:"white"};
$.ajax({
type: "POST",
url: "test",
data: { disciplines:disciplines },
dataType: "Json",
success: function (response) {
},
beforeSend: function () {
showIndicator();
},
error: onFailure,
});
当我调试它时,控制器参数始终为null。 我怎么能成功地做到这一点。非常感谢。
答案 0 :(得分:1)
您的代码应为
SELECT Datename(weekday, time) AS weekday,
( ( Datepart(hour, time) / 3 ) - 3 ) AS segment,
Count(*) AS num_transactions
FROM "transaction"
GROUP BY Datename(weekday, time),
( ( Datepart(hour, time) / 3 ) - 3 )
ORDER BY CASE Datename(weekday, time)
WHEN 'Monday' THEN 1
WHEN 'Tuesday' THEN 2
WHEN 'Wednesday' THEN 3
WHEN 'Thursday' THEN 4
WHEN 'Friday' THEN 5
WHEN 'Saturday' THEN 6
WHEN 'Sunday' THEN 7
END,
( ( Datepart(hour, time) / 3 ) - 3 );
<强>控制器强>
var disciplines = {"Id":1, "Name":"white"};
$.ajax({
type: "POST",
url: "test",
data: { disciplines:disciplines },
dataType: "Json",
success: function (response) {
},
beforeSend: function () {
showIndicator();
},
error: onFailure,
});
必须具有与类
中相同的参数名称答案 1 :(得分:1)
问题是因为模型活页夹会在请求中查找name
和disciplines
属性,而不是var disciplines = {
id: 1,
name: "white"
};
$.ajax({
type: "POST",
url: "test",
data: disciplines,
dataType: "json",
success: function (response) {
},
beforeSend: function () {
showIndicator();
},
error: onFailure,
});
。试试这个:
var str:String = 'Hello World!';