Ravi Patel

Ravi Patel

  • 271
  • 6.8k
  • 1.4m

How to return html code from web api

Mar 18 2019 5:47 AM
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)