【发布时间】:2013-07-04 12:11:53
【问题描述】:
如何将DataTable 作为参数传递给控制器。当我使用以下代码时,data 始终为空。
对象
public class Notification
{
public int UserId { get; set; }
public DataTable Profiles { get; set; }
}
控制器
[HttpPost]
public HttpResponseMessage UpdateNotification(Notification data)
{
if(data == null)
{
//data is always null here
}
}
通过 POSTMAN 请求
Content-Type: application/json
{
UserId: 1,
Profiles: [1,2]
}
当我删除 Profiles 时,它工作正常。但是在拥有参数时,data 始终为空。有什么问题吗?
【问题讨论】:
-
这行不通,因为模型绑定器不知道如何处理 DataTable 对象。如果您真的想做这件事,那么您必须自己编写一个自定义模型绑定器。
-
@Yellowfog,你能给出一些想法吗?
标签: c# asp.net-mvc-4