Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add views to ASP.NET Core Web API?

Controllers process requests and return views in ASP.NET MVC, but how to add presentation layer (views or html pages) in ASP.NET Core Web API? I need to show to the user not the IEnumerable collection of objects, but a real webpage. Sorry for the stupid question.

like image 836
TryBetter Avatar asked Oct 15 '25 14:10

TryBetter


1 Answers

Add MVC packages if not available from nuget package manager

using Microsoft.AspNetCore.Mvc;

add this line to startup.cs

//replace => services.AddControllers();
services.AddControllersWithViews();

I hope you will be able to use MVC feature from now.

like image 104
Sudhananda Biswas Avatar answered Oct 18 '25 02:10

Sudhananda Biswas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!