Hello so i download a File but if it doesent find the right values there will be an error Message. Now after entering the correct Data the File is sucesfully downloaded, but the error Message is still there. I have a Button Generate Report that calls this function.
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<br /><br />
<input type="submit" name="generateReport" value="Generate Report" class="button button--small button--primary" />
</div>
</div>
public ActionResult Index(ReportingModel reportingModel, string aaa)
{
if (reportingModel.FromDate > reportingModel.ToDate)
{
ModelState.AddModelError("CustomError", "Date range not correct");
return RedirectToAction("Index", reportingModel);
}
var path = Server.MapPath(@"~/App_Data/Templates/File.xlsx");
var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
var liste = reportingService.GetMarketRiskData(reportingModel.FromDate, reportingModel.ToDate, reportingModel.BenchmarkIds, reportingModel.TenorIds);
if (liste.Count() > 0)
{
var reportDataStream = reportingService.GenerateReport(fileStream, liste);
ModelState.Clear();
ViewBag.JavaScriptFunction = "Hello";
return File(reportDataStream.ToArray(), "application/xlsx", $"{DateTime.Today:yyyyMMdd}_RAD_MarketRisk.xlsx");
}
ModelState.AddModelError("CustomError", "NO rows found in given selection");
FillViewBagData();
return View(reportingModel);
}
Ad you can see i try to Clear the Model State but because the Page doesent Refresh the model state isnt cleared. There would be some ideas to refresh the page later via JavaScript but that could be inconsistent.
Thanks for the Help:)