I am new to MVC. I have an index page. Which displays a list of items to the user. The user can then add a new item. After the user has added the new item a file is downloaded for them containing sensitive the information they added. All of that works fine but....
My problem is now how to redirect them back to the index page to refresh the list of items? Its almost like I need a redirect after the download.
Note: Insert download all work fine. I am just trying to figure out how to do a redirect to another model after the download so that I can refresh my list.
I cant do the redirect first because the data that is being saved to the file is sensitive so I don't want to send it anywhere.
[Authorize]
public async Task<IActionResult> Index(int clientId, string error)
{
// ....... Removed
var model = new SecretIndexModel()
{
Client = clients.Client,
ErrorMessage = error
};
return View(model);
}
On this page, a user can add a new item.
[Authorize]
[HttpPost]
public async Task<IActionResult> Add(SecretIndexModel model)
{
/// removed ....
return DownloadDocument("results json string");
}
Download
public FileResult DownloadDocument(string id)
{
var ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes("abc"));
return File(ms, System.Net.Mime.MediaTypeNames.Application.Octet, "secret.json");
}
Am I going about this wrong? I know I need to add something like this because that works if I return that instead of the download.
return RedirectToAction("Index",
new
{
clientId = model.Client.Id,
error = (client.Errors == null)
? string.Empty
: client?.Errors?.FirstOrDefault()?.Message
});
Update:
I can send the data over using TempData
but that doesn't seem to help much I can then refresh the index page but not download the file.