2
是否可以将ViewModel对象传递给WebApi控制器操作而不是单独的参数?将ViewModel传递给Web-Api操作
而不是使用:
public class ContactsController : ApiController
{
public IEnumerable<Contact> GetContacts(string p1, string p2)
{
// some logic
}
}
我想用:
public class ContactsController : ApiController
{
public IEnumerable<Contact> GetContacts(TestVM testVM)
{
// some logic
}
}
public class TestVM
{
public string P1 { get; set; }
public string P2 { get; set; }
}
这似乎并不为我工作。当我打电话给/ api/contacts /?P1 = aaa & P2 = bbb testVM对象没有被填充(null)。
而且,我想TestVM有定义valdiation attribtues和我的API控制器使用ModelState.IsValid。