I'm trying to use Attribute Routing and having a difficult time getting different parameters to work. When I search by Name (second routine below) I get the error: "IIS 8.0 Detailed Error - 404.0 - Not Found". When I search by ID it works fine after I added the ":int" to the Route attribute.
How can I implement a Search by Name which is a string field in this scenario? I need to continue to use Attribute Routing.
Here is the Controller Code:
[Route("api/section/{id:int}")]
[HttpGet]
public string Get(int id)
{
return "Searching By ID"
}
[Route("api/section/{sectionname}")]
[HttpGet]
public string GetByName(string sectionName)
{
return "Search By Name";
}
Here is the WebApiConfig.cs code:
public static void Register(HttpConfiguration config)
{
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}