我有以下異步方法:[HttpGet][Route("api/SecurityRoles/AllowDeleteRole/{securityRoleId}")]public async Task<IHttpActionResult> AllowDeleteRole(int securityRoleId){ _systemLogger.LogInfo($"Method api/SecurityRoles/AllowDeleteRole (Get) called with securityRoleId: {securityRoleId}"); var securityRolePermission = await _securityRolePermissionService.SecurityRolePermissionsCountBySecurityRoleId(securityRoleId); if (securityRolePermission != SecurityRoleDeleteResult.Success) return Ok(SecurityRoleDeleteResult.RolePermissionExists); var securityRolePageEntity = await _securityRolePageEntityService.SecurityRolePageEntityCountBySecurityRoleId(securityRoleId); return Ok(securityRolePageEntity != SecurityRoleDeleteResult.Success ? SecurityRoleDeleteResult.RolePageEntityExists : SecurityRoleDeleteResult.Success); }它在很多地方使用,但對于這個實例,我需要非異步地使用它,所以我有以下代碼首先包裝它:public async Task<SecurityRoleDeleteResult> AllowDeleteRole(int securityRoleId) { string url = $"{_housingDataSecurityConfiguration.HousingDataSecurityWebApiUrl}SecurityRoles/AllowDeleteRole/{securityRoleId}"; var message = _apiClientService.Retrieve<HttpResponseMessage>(url); if (message.StatusCode == HttpStatusCode.InternalServerError) { return SecurityRoleDeleteResult.ErrorOccurred; } int intResult = 0; var apiResult = await message.Content.ReadAsStringAsync(); if (int.TryParse(apiResult, out intResult)) { return (SecurityRoleDeleteResult)intResult; } else { return SecurityRoleDeleteResult.ErrorOccurred; } }我的問題是,當我嘗試EnableDeleteButton = enableButton在模型中進行設置時,它會在線上拋出以下錯誤:enableButton = (result.Result == SecurityRoleDeleteResult.Success) ? true : false;{"將值 3 轉換為類型 'System.Net.Http.HttpResponseMessage' 時出錯。路徑 '',第 1 行,位置 1。"}3 指的是我的 SecurityRoleDeleteResult 枚舉上的枚舉值之一。
- 1 回答
- 0 關注
- 202 瀏覽
添加回答
舉報
0/150
提交
取消