如何将C#Asp.Net IActionResult转换为字符串?

时间:2018-10-13 14:44:24

标签: c# asp.net-core

此方法:

public IActionResult Index(string CatId)

可能退货

NotFound("Cat does not exist");

this.Content(catname);

但是,如果找到了猫,这就是实际返回的信息:

Microsoft.AspNetCore.Mvc.ContentResult

如何获取我真正想要的字符串?

1 个答案:

答案 0 :(得分:-2)

public IActionResult Index(string CatId)
        {
          string catName=null;
            try
            {
           /*your code to get catname*/
                if (catName != null)
                {
                    return Ok(catName);
                }
                return NotFound();

            }
            catch (Exception e)
            {
                return  InternalServerError(e);
            }
        }