将StringContent返回给客户端以显示消息

时间:2015-06-11 14:35:34

标签: json angularjs asp.net-web-api2

我有一个休息服务,我必须做一个可以返回一个或零对象的get ..如果我找到它,这里返回的对象:

<select th:field="*{type}">
  <option th:each="type : ${allTypes}" 
          th:value="${type}" 
          th:text="#{${'seedstarter.type.' + type}}">Wireframe</option>
</select>

如果我找到一个对象,我可以正确地将它返回给客户端...如果我找不到任何内容,我想返回一条消息,建议用户没有找到任何内容:

public class FollowXMessage
{
    public string UploadFolder { get; set; }
    public int Status { get; set; }
    public int CustomerType{ get; set; }
}

客户端我想以这种方式管理结果:

if (found)
{
    ...
    return Ok(result); //result is FollowXMessage
}
else if (!found)
{
    return Ok(new StringContent("Nothing Found", System.Text.Encoding.UTF8, "text/plain"));
}

//In all other cases there has been raised an exception
return BadRequest("Some errors");

问题是我从未收到过字符串......如果没有返回任何对象,我会收到此回复:

enter image description here

我的留言在哪里&#34;没有找到&#34;?

谢谢

0 个答案:

没有答案
相关问题