如何在blazor页面上显示api返回的text/html


@page "/counter"
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@if (currentCount % 2 == 0)
{
<iframe width="1660" height="1115" src="https://www.youtube.com/embed/m8e-FF8MsqU" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
}
else
{
<iframe width="1660" height="1115" src="http://localhost:10726/api/Employee/HtmlReport" frameborder="0" allowfullscreen></iframe>
}

@code {
int currentCount = 0;
void IncrementCount()
{
currentCount++;
}
}

下面是返回的text/html/在此处输入图像描述

但是,它不能显示在blazor页面上,但会被下载。如何做到:在此处输入图像描述

我在这里使用代码:在此处输入链接描述

谢谢!

正如@Henk Holterman所说,问题出在后端代码中。这是一个工作演示:

[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
// GET: api/<ValuesController>
[HttpGet]    
public async Task<IActionResult> Get()
{
string filePath = "test.pdf";  //test.pdf located in wwwroot folder
var contentDisposition = new System.Net.Mime.ContentDisposition
{
FileName = "test.pdf",
Inline = true
};
Response.Headers.Add("Content-Disposition", contentDisposition.ToString());
return File(filePath, System.Net.Mime.MediaTypeNames.Application.Pdf);
}
}

索引.razor:

<iframe width="1660" height="1115" src="https://localhost:44304/api/values" frameborder="0" allowfullscreen></iframe>

相关内容

  • 没有找到相关文章

最新更新