Masu Thư
Masu Thư

Reputation: 1

C# ASP MVC: How to create a variable to execute this method

I am practicing the demo MVC 2.0, but when I create a variable, Visual Studio shows an error

Cannot assign method group to an implicitly-typed local variable

Can you help me to resolve the problem? Here's the code:

public ActionResult ShowAllProducts()
{
    var allProducts = repository.FindAllProducts;
    return View(allProducts);
}

Upvotes: 0

Views: 59

Answers (2)

Kayani
Kayani

Reputation: 972

FindAllProducts is a method so it requires braces

 var allProducts=repository.FindAllProducts();

Upvotes: 0

İsmet Alkan
İsmet Alkan

Reputation: 5447

Just add () to the end of the line:

var allProducts = repository.FindAllProducts();

Upvotes: 2

Related Questions