TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ravi Patel
275
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();
}
Reply
Answers (
5
)
An item with the same key has already been added
.NET Web API action method's attributes FromBody and FromUri