Didn"t forge 2009-02-16 17:44 采纳率: 25%
浏览 285
已采纳

在 MVC 中,我如何返回一个字符串结果?

In my AJAX call, I want to return a string value back to the calling page.

Should I use ActionResult or just return a string?

转载于:https://stackoverflow.com/questions/553936/in-mvc-how-do-i-return-a-string-result

  • 写回答

4条回答

  • 三生石@ 2009-02-16 17:47
    关注

    You can just use the ContentResult to return a plain string:

    public ActionResult Temp() {
        return Content("Hi there!");
    }
    

    ContentResult by default returns a text/plain as its contentType. This is overloadable so you can also do:

    return Content("<xml>This is poorly formatted xml.</xml>", "text/xml");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services