Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebAPI and razor view engine

I am using MVC4 from Visual Studio 2012. when creating a Web API project from VS project template, the wizard dialog shows only the Razor view engine is select-able. My question is why a View is needed for a Web API project and then why Razor only? I tried to add API controller to both Razor and ASPX engine web applications, the result shew both work. So, is this an issue of Web API project template?

like image 384
Shuping Avatar asked May 27 '26 19:05

Shuping


1 Answers

ASP.NET MVC and Web API are based on ASP.NET however, they are not integrated with it. Therefore, when making an ASP.NET or ASP.NET MVC project, you CAN use WebAPI just as you can use WCF. However, when creating WebAPI projects there should be no reason to rely on ASP.NET, but allow application to be self-hosted.

New ASP.NET MVC project can use both Razor and WebForms for page rendering, and it is hosted as ASP.NET web application.

New Web API project doesn't need ASP.NET nor WebForms and does not have to be hosted as ASP.NET application. It doesn't even need Razor as there's no need for a view engine, but project template is such to allow novice programmer to have a project that 'just runs' in few clicks, and then displays a help page. So you don't need Razor, and you can self host a Web API application.

like image 178
Nikola Radosavljević Avatar answered May 30 '26 08:05

Nikola Radosavljević



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!