This is the method in my Model :
public IList<Customer> GetProfileCustomer(int id)
{
var list_customer = from c in DataContext.Customers
where c.ID == id
select c;
return list_customer.ToList();
}
And this is what I did in my controller :
public ActionResult ShowProfile()
{
List<CustomerModels> cus = new List<CustomerModels>();
return View();
}
I created the object cus to call the method GetProfileCustomer() in the model, but I cannot do that. When I write : cus.GetProfileCustomer, It is error.
Your major issue is the line:
That is not creating an instance of
CustomerModels, so you can’t call that method on it. You would have to do something like:However, in the MVC sense, I don’t think loading data from your Model is really the right approach. Typically the Controller has some reference to something else that loads and saves data. The Model is usually just a class with properties to hold the data.
I would look at the “NerdDinner” sample project. For example, in these files:
Note that
DinnersControllerholds a reference to a dinner repository, which is the thing that queries the database.