here is what is happening
- If I copy paste my endpoint URL(https://localhost:44348/api/TestController1) in the browse and press enter then it is working, file will be downloaded
- but if I press the button then it is not working
Below are my code current snippets
Api Controller Code:
// GET: api/<TestController1>
[HttpGet]
public ActionResult Get()
{
JsonObject jsonObject = new JsonObject()
{
Name = "Keval Chauhan",
EnrollmentNumber = 1234567890
};
var serializedObject = JsonConvert.SerializeObject(jsonObject, new JsonSerializerSettings());
byte[] bytes = Encoding.UTF8.GetBytes(serializedObject);
var stream = new MemoryStream(bytes);
var result = new FileStreamResult(stream, "text/json");
result.FileDownloadName = "test.json";
return result;
}
Blazor Page Code that is executed on button press:
public async void DownloadJSON()
{
HttpClient httpClient = new HttpClient();
await httpClient.GetAsync("https://localhost:44348/api/TestController1");
}