-
-
Save csharpfritz/fb608b1fd8811e7332fd341bd50685ca to your computer and use it in GitHub Desktop.
ASP.NET Core Controller with MVC and API actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProductController : Controller { | |
private readonly ProductRepository _repository; | |
public ProductController(ProductRepository repository) { | |
_repository = repository; | |
} | |
[Route("/api/Product/{id}")] | |
public Product Get(int id) { | |
return _repository.Get(id); | |
} | |
[Route("/Product")] | |
public ActionResult Index() { | |
var allProducts = _repository.GetAll(); | |
return View(allProducts); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_repository
_repository
readonly
ProductRepository