Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
Return file but clear Model State C#

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:)

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda