I'm attempting to create a Web API method with a custom route that takes in a String parameter, but this appears to error upon application start - so I don't even need to hit the route or the method for the application to break.
// Pass String to TMS and Return an ID
[System.Web.Http.HttpGet]
[System.Web.Http.Route("api/job/import/{import:string}")]
public int TmsImport(string import)
{
var TmsId = 0;
if (import.Length > 0)
{
TmsId = 1;
}
return (TmsId);
}
The application breaks on the following method in Global.asx:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
This same method works when I pass an int to the method, but it doesn't seems to able to recognise the name 'string' in the parameter. I did see an answer to a similar question here: call to web api with string parameter - but I can't figure out where the change would be from that answer? If it would be in the call from the JS or in the route config?