'TestController.Post()':并非所有代码路径都返回值

编程入门 行业动态 更新时间:2024-10-27 12:30:27
本文介绍了'TestController.Post()':并非所有代码路径都返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在返回 HttpResponseMessage ,但是我的代码仍然抱怨并抛出错误,

I am returning HttpResponseMessage, but still my code complains and throw below error,

'TestController.Post()':并非所有代码路径都返回值

'TestController.Post()': not all code paths return a value

这里返回什么?

public async Task<IHttpActionResult> Post() { var response = await IsDataValid(); if (response) return Ok(new HttpResponseMessage(HttpStatusCode.OK)); }

推荐答案

您只需要再添加几行代码即可解决上述错误.

You need to add just few more line of code to deal with the above error.

public async Task<IHttpActionResult> Post() { var response = await IsDataValid(); if (response) return Ok(new HttpResponseMessage(HttpStatusCode.OK)); else return NotFound(); }

其他部分在这里很重要.

The else part is important here.

更多推荐

'TestController.Post()':并非所有代码路径都返回值

本文发布于:2023-11-10 01:21:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573973.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   返回值   代码   TestController   Post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!