asp.net mvc 中的 response.write 是什么? [英] what is response.write in asp.net mvc?

查看:20
本文介绍了asp.net mvc 中的 response.write 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这会很简单,但是

在 asp net MVC 中使用经典网络表单response.write"的最佳方式是什么.尤其是mvc5.

What is the best way of using classical webforms "response.write" in asp net MVC. Especially mvc5.

比方说:我只想写一个简单的字符串来从控制器中筛选出来.

Let's say: I just would like to write a simple string to screen from controller.

mvc 中是否存在 response.write?

Does response.write exist in mvc?

谢谢.

推荐答案

如果你的方法的返回类型是ActionResult,你可以使用Content方法返回任何类型的内容.

If the return type of your method is an ActionResult, You can use the Content method to return any type of content.

public ActionResult MyCustomString()
{
   return Content("YourStringHere");
}

或者干脆

public String MyCustomString()
{
  return "YourStringHere";
}

内容 方法也允许您返回其他内容类型,只需将内容类型作为第二个参数传递即可.

Content method allows you return other content type as well, Just pass the content type as second param.

 return Content("<root>Item</root>","application/xml");

这篇关于asp.net mvc 中的 response.write 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆