How to return raw string with ApiController?

前端 未结 6 886
萌比男神i
萌比男神i 2020-11-29 21:49

I have an ApiController that serves XML/JSON, but I would like one of my actions to return pure HTML. I tried the below but it still return XML/JSON.

public          


        
6条回答
  •  没有蜡笔的小新
    2020-11-29 22:24

    Another possible solution. In Web API 2 I used the base.Content() method of APIController:

        public IHttpActionResult Post()
        {
            return base.Content(HttpStatusCode.OK, new {} , new JsonMediaTypeFormatter(), "text/plain");
        }
    

    I needed to do this to get around an IE9 bug where it kept trying to download JSON content. This should also work for XML-type data by using the XmlMediaTypeFormatter media formatter.

    Hope that helps someone.

提交回复
热议问题