5
Answers

How to return html code from web api

Ravi Patel

Ravi Patel

5y
20.2k
1
Hi All,
 
i want to return  html code from web api
 
i have done 
 
public HttpResponseMessage Get()
{
string Filepath = HttpContext.Current.Request.MapPath(@"~/Template1/Receipt1.html");
string Html = File.ReadAllText(Filepath);
StringBuilder sb = new StringBuilder(Html);
var response = new HttpResponseMessage();
response.Content = new StringContent(sb.ToString());
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
response.ReasonPhrase = "success";
return response;
}
 
above is working fine  but i want to use IHttpActionResult 
 
public IHttpActionResult Get()
{
string Filepath = HttpContext.Current.Request.MapPath(@"~/Template1/Receipt1.html");
string Html = File.ReadAllText(Filepath);
StringBuilder sb = new StringBuilder(Html);
 
// what code should i write here
return Ok();
}
Answers (5)