我的路径是: HttpGet公共IResult GetStreetsOfCityByText(int cityCode,string txt) {….}字符串txt可以为空。为了启用可空参数,我使用了MapHttpRoute: config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute( name:"optionalText",routeTemplate: optionalText默认值:routeTemplate{ txt = RouteParameter.Optional });我尝试调用:http://localhost:56721/General/GetStreetsOfCityByText/3000/,但仍然得到404页未找到,我不明白我做错了什么
发布于 2018-02-01 17:41:10
有人向我展示了一个解决方案:在路由模板中,在可空参数之前添加一个*。如下所示: Route("General/GetStreetsOfCityByText/{cityCode}/{*txt}"),这告诉我们这个参数可能不存在于调用URL中
https://stackoverflow.com/questions/48558278
复制