Hi all!
I need to return HTML response without using the razor, is it possible?
Hi all!
I need to return HTML response without using the razor, is it possible?
Sure see docs on returning different response types or you can return a static .html file.
The default content-type when requested from a browser is text/html
but you can ensure text/html
is always the content-type by specifying the HTML Content-Type, e.g:
[AddHeader(ContentType = "text/html")]
public string Get(HelloHtml request)
{
return $"<h1>Hello, {request.Name}!</h1>";
}
I want to return a static HTML file, where the error notification access to the downloadable file.
Of course I can write all the markup in the code but it is not very convenient
Is there such a possibility?
You can use return a static file with new HttpResult(FileInfo, asAttachment:downloadAsAttachment)
with the downloadAsAttachment
flag indicating whether you want it downloaded as a file or returned as normal html. You can set any additional HTTP Info you need on the HttpResult
, e.g. StatusCode
or Headers
.
ok, I’ll try, thanks !!!