MVC4 WebAPI projemde yönlendirmeyi yapılandırmaya çalışıyorum.Sorgu dizesi parametre adı temelinde yönlendirme
Ben kendi adına ya da öylesine gibi onların türüne göre ürünler için arama yapabilmek istiyorum:
/api/products?name=WidgetX
- WidgetX /api/products?type=gadget
adlı tüm ürünlerini döndürür - yolları vardır
tipi gadget tüm ürünleri döndürür böyle yapılandırılmış:
config.Routes.MapHttpRoute(
name: "Get by name",
routeTemplate: "api/products/{name}",
defaults: new { controller = "ProductSearchApi", action = "GetProductsByName", name = string.Empty }
);
config.Routes.MapHttpRoute(
name: "Get by type",
routeTemplate: "api/products/{type}",
defaults: new { controller = "ProductSearchApi", action = "GetProductsByType", type = string.Empty }
);
sorun sorgu dizesi parametresi adı ilk güzergah kullanılır hep bu yüzden ne olursa olsun, ihmal gibi görünüyor olmasıdır sorgu dizesi parametresinin adı. Doğru yapmak için rotamı nasıl değiştirebilirim?
RouteParameter beni tabii ihtiyacını karşılamak olmaz ürünler/abc/gibi bir URL ile kullanmak olur. Sorgu dizesi parametrelerini kullanabilmem gerekir. – rickythefox