Viewdata is not displaying message

Asked

Viewed 163 times

1

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 method Verificar() from Controller, is calling correctly, and returns the message from Viewdata.

I debugged the code and the following error is appearing in Viewdata:

inserir a descrição da imagem aqui

Controller

public ActionResult Verificar()
    {
        string Feedback = string.Empty;
        var DadosTemporarios = NDados.BuscaScanIDTemporaria();
        var DadosVulnExistentes = 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>
  • You will show the Viewdata message only when you click the check button ?

  • After calling Check and return to Index method.

3 answers

1

Try to use it straight:

@ViewData["Feedback"]

1

Why use Html.Encode ?

Use @Viewdata["Feedback"]

  • The same thing happened Kevin.

  • Html.Encode converts a specific object value into string in HTML.

0

Try this way:

<p> <%: ViewData["FeedBack"] %> </p>

but in this way:

<p> <%= ViewData["FeedBack"] %> </p>
  • It didn’t work, Thiago.

  • strange, try to change to post the ajax and put on top of the controller method the [Httppost]

  • I tried to do it and it didn’t work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.