what is response.write in asp.net mvc?

前端 未结 2 1069
野的像风
野的像风 2021-01-06 04:55

This will be quite simple but

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

Let\'s say: I just would l

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-06 05:30

    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");
    }
    

    or simply

    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("Item","application/xml");
    

提交回复
热议问题