Error opening View with values loaded directly from class

Asked

Viewed 45 times

1

I have a default Login screen, which has the functionality "I forgot the password", which when clicked will check the number of the user ID typed on the screen, and if respected, will open a new View with this message:

Note EXPOSURE = dbo.Clientes.Cliemail

"We send an email to the address EXPOSURE with instructions from recovering"

But in the method that should return this data to view from this error:

Stack

Invalidoperationexception: The model item passed into the Viewdatadictionary is of type 'System.String', but this Viewdatadictionary instance requires a model item of type 'PCI.EV.Models.Customers'.

Follow code.

Accountscontroller(method that queries the email according to the ID):

 public IActionResult ForgetMyPassword(Clientes cli)
        {
            Clientes objCli = new Clientes();
           var client = objCli.ConsultarEmail(cli.CliCodigo, _config);
            if (client != null)
            {
                return View("RememberPassword", client);
            }
            return View("Login");
        }

in the client variable is loaded the email, but it does not open the View.

inserir a descrição da imagem aqui

Message view(Rememberpassword)

Note. Both the Login view and the Rememberpassoword view belong to the same controller.

@model PCI.EV.Models.Clientes
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>RememberPassword</title>
    <environment include="Development">
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
        <link rel="stylesheet" href="~/css/site.css" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
              asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
              asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
        <link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
    </environment>
    <environment include="Development">
        <script src="~/lib/jquery/dist/jquery.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
        <script src="~/js/site.js" asp-append-version="true"></script>
    </environment>
    <environment exclude="Development">
        <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js"
                asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
                asp-fallback-test="window.jQuery"
                crossorigin="anonymous"
                integrity="sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk">
        </script>
        <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"
                asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
                asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
                crossorigin="anonymous"
                integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa">
        </script>
        <script src="~/js/site.min.js" asp-append-version="true"></script>
    </environment>
</head>
<body>
    <div class="container body-content">
        <div class="form-group">

            <br />
            <label class="control-label">Enviaremos um e-mail  com instruções para redefinição de senha.</label>
            <input type="email" asp-for="CliEmail" style="width: 150px" />
            <br />

        </div>
    </div>
</body>

</html>

1 answer

1


Read the error:

Invalidoperationexception: The model item passed into the Viewdatadictionary is of type 'System.String', but this Viewdatadictionary instance requires a model item of type 'PCI.EV.Models.Clients'.

In the view you restrict the model to the type Clientes (@model PCI.EV.Models.Clientes) and when calling the method View() you try to pass a string as a parameter.

You probably want to restrict the type of view for string.

That’s what the first line is for

@model PCI.EV.Models.Clientes
<!DOCTYPE html>
<!-- Resto do código -->

Browser other questions tagged

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