Monday, April 25, 2016

WebAPI plain text response

I got a problem where the solution was to create a globe JavaScript object and I need to render the data on the server.

I would like to use the JavaScript object like:

<span id="text"></span>
<script>
var d = document.getElementById("text");
d.innerText = resources.hello;
</script>

I started by creating a WebAPI controller and return a string through the Ok method. And end up with this:

clip_image001

This is not JavaScript and there for I can’t use it.

I found an article by Mike Wasson (http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/action-results). Where he creates a new IHttpActionResult.

With this new class. I can control the output. So it will be like this:

clip_image002

No comments:

Post a Comment