【发布时间】:2021-09-24 09:07:05
【问题描述】:
我的控制器中有这段代码:
string APIBaseurl = "https://sub.domain.de/";
[Route("VerseExkurs/Technologien/{technologie}")]
public async Task<ActionResult> Details(string technologie)
{
TechnologieRootobject TechnologieInfo = new TechnologieRootobject();
using (var client = new HttpClient())
{
//Passing service base url
client.BaseAddress = new Uri(APIBaseurl);
client.DefaultRequestHeaders.Clear();
//Define request data format
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//Sending request to find web api REST service resource GetAllEmployees using HttpClient
HttpResponseMessage Res = await client.GetAsync("items/technologien/" + technologie + "?access_token=token");
//Checking the response is successful or not which is sent using HttpClient
if (Res.IsSuccessStatusCode)
{
//Storing the response details recieved from web api
var TechnologieResponse = Res.Content.ReadAsStringAsync().Result;
//Deserializing the response recieved from web api and storing into the Employee list
TechnologieInfo = JsonConvert.DeserializeObject<TechnologieRootobject>(TechnologieResponse);
}
//returning the employee list to view
return View(TechnologieInfo.data);
}
}
但问题是,“{technologie}”变量在某些情况下带有空格。有没有办法自动转换下划线中的空格?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-routing