I am implementing it so I can load a json file as an options file and persist the changed data if the need be. I followed this SO question and I have it properly working the file saves and I successfully get the trigger for reload on change. However when I POST
the action and update the information and at the end execute RedirectToAction("Index")
it doesn't seem to update the Transient. After it returns the Redirect the page is in the same state as before the POST
, however when I manually press F5 to refresh the page the proper data is now showing.
I have tried things like RedirectToAction("Index", "Admin")
and tried looking into having the transient update every action or writing my own but can't find anything to help me even start doing that.
It would be helpful to understand what IWritableOptions
is when looking at the link above. The only thing I changed is instead of giving it a section it loads the whole file.
private readonly IWritableOptions<Settings> settings;
public AdminController(IWritableOptions<Settings> settings)
{
this.settings = settings;
}
public IActionResult Index()
{
// Loading for the first time all is good and settings values are valid
// After being RedirectToAction from the HttpPost the data hasn't updated to the new values.
// If I manually refresh the page all data is correctly set to the new values. (Same if I leave the page and come back)
return View(settings.Value);
}
[HttpPost]
public IActionResult General(SettingsViewModel model)
{
settings.Update(opts =>
{
opts.Value1 = model.Value1 ;
opts.Value2 = model.Value1 ;
});
return RedirectToAction(nameof(Index));
}
The expected results is after the RedirectToAction the settings values are now set to their new values. I think this has to do with using AddTransient
where it only refreshes on a full controller reload but am not 100% positive from my reading. I am up for any possibility to get this working properly...