View call @model of the controller

Asked

Viewed 314 times

2

I use the EF Design and import all my models from the bank to a .EDMX.

I ask you: How do I call the objects of controllers that I create, within a View?

I’ve tried to put @model up to the controller and will not and I tried to create a list of an object from controller neither will.

  • Please put how you set up your controller and view so we can know what you did wrong and show you what to fix.

  • Actually it’s not the View that "calls the objects of the controllers", but yes he, the controllers, passing the information to the View. The @Rtur-Peixoto answer your question correctly.

1 answer

4

Dude, I don’t think you’re getting the object to View, that’s it?

//Instância para acessar o banco de dados
private ApplicationDbContext ctx = new ApplicationDbContext();

public ActionResult Details(int Id)
{

    var model = ctx.Objeto.Find(Id)
    return View(model);
} 

You place the object within the parameter of view() and in the HTML you just put the object model:

@model Solution.Objeto

then just call the @Model.Id or other property you want to take from the object.

Browser other questions tagged

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