可以使用jQuery的ajax方法将空对象发送到控制器。以下是一个示例代码:
在View中的JavaScript代码:
var data = {}; // 空对象
$.ajax({
url: '@Url.Action("ActionName", "ControllerName")',
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify(data),
success: function(result) {
// 处理返回的结果
},
error: function(xhr, status, error) {
// 处理错误
}
});
在Controller中的方法:
[HttpPost]
public ActionResult ActionName(MyModel model)
{
// 在这里处理传递过来的空对象
// ...
return Json(result);
}
其中,MyModel
是你的模型类,用于接收传递过来的数据。通过将空对象data
使用JSON.stringify
方法转换为JSON字符串,并设置contentType
为application/json
,然后使用POST方法将数据发送到控制器。
在控制器的方法中,使用MyModel
参数接收传递过来的数据,然后进行相应的处理。最后,使用Json
方法返回结果给前端。