I'm trying to send a message from Controller to View, using ViewData, but it's not displaying the message.
When I click on the "Check" button of the View it is to call the Verificar()
method of the Controller, it is calling correctly, and returns the ViewData message.
I've debugged the code and the following error is appearing in the ViewData:
Controller
publicActionResultVerificar(){stringFeedback=string.Empty;varDadosTemporarios=NDados.BuscaScanIDTemporaria();varDadosVulnExistentes=NDados.BuscaScanIDVulnExistentes();if(DadosTemporarios.ScanID==DadosVulnExistentes.ScanID){Feedback="ScanID Iguais!";
}
else
{
Feedback = "ScanID Diferentes!";
}
ViewData["Feedback"] = Feedback;
return View("Index", ViewData["Feedback"]);
}
View
<script>
function VerificaDados() {
$.ajax({
url: '/UploadDados/Verificar',
type: "GET"
});
};
</script>
<div class="container">
<h3><strong>Importar Tabela de Vulnerabilidades</strong></h3>
<hr />
@using (Html.BeginForm("Index", "UploadDados", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="form-group">
<label for="anexo">Anexar Arquivo CSV</label>
<input type="file" id="FileUpload" name="FileUpload" />
</div>
<p>@Html.Encode(ViewData["Feedback"])</p>
<p>
<button class="btn btn btn-warning" type="submit" onclick="submitForm()">Upload</button>
<button class="btn btn btn-warning" type="button" onclick="VerificaDados()">Verificar</button>
</p>
}
</div>