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。