У меня создалось впечатление, что привязка к модели в ASP.Net Web API должна поддерживать привязку с тем же минимальным уровнем функциональности, который поддерживается MVC.
Возьмите следующий контроллер:
public class WordsController : ApiController
{
private string[] _words = new [] { "apple", "ball", "cat", "dog" };
public IEnumerable<string> Get(SearchModel searchSearchModel)
{
return _words
.Where(w => w.Contains(searchSearchModel.Search))
.Take(searchSearchModel.Max);
}
}
public class SearchModel
{
public string Search { get; set; }
public int Max { get; set; }
}
Я запрашиваю его с помощью
http://localhost:62855/api/words?search=a&max=2
К сожалению, модель не связывается, как в MVC. Почему это не является обязательным, как я ожидал? В моем приложении у меня будет много разных типов моделей. Было бы неплохо, если бы привязка просто работала, как в MVC.