ASP.NET Form MVC 5 cannot access Model properties

Asked

Viewed 201 times

0

I am starting at ASP.NET MVC, following tutorials and handouts on the internet I created a study project and I have some doubts.

Well, first I’ll create a class structure to follow:

> Acesso -> Possui informações de identificacao(Login e Senha) 
> Nivel_Acesso -> Define o nível de acesso de um determinado "ACESSO"
> Cliente -> Guarda os dados do cliente e possui Acesso e Endereco
> Endereco -> Armazena Endereco do cliente

I created a Context class that maps all these entities, as well as a controller responsible for logging in and viewing this controller. The problem is precisely in this Login view, because when I try to declare the model at the top of the document "Login.cshtml" the model seems not to be being "viewed" from the view. I say this because when inserting the line -> @Model "Project Name(ENDPOINT)" it does not display project directories.

And when I try to access some property of the model, it seems that the object is empty.

Follow the screen:

inserir a descrição da imagem aqui

The other doubt is related to the Entity-framework, because it seems to have worked normally when creating the bank for the first time, however I ended up dropping the DB. Now when I start the project, the database is not created again by the Entity-framework. I even tried to create a Migration and give Update-Database, but it had no effect on the database.

  • I tried to clean the project and then build, even so the view does not seem to fill the model. The namespace is correct too and therefore no longer know what to do... as for the Entity framework I tried to change the connection string and give update-database in powershell.

1 answer

2


Your problem is in the way you declare the type of View.

A type must be declared with the @model, and not with @Model, i.e., model in lower case.

For use should use the Model

Example:

@model ProjetoWeb.Models.Cliente

@if (Model != null)
{
   @*realiza um processo*@
}

Browser other questions tagged

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