[英]What is the best way to handle the view routing in Web API Razor
I have this doubt, because always when I create a Web API project I use the API controllers to get data and I create a normal controller where I define all my methods that returns ActionResult to redirect to the views and I am not sure if this is the best way. 我有这个疑问,因为总是在创建Web API项目时使用API控制器来获取数据,并创建一个普通的控制器,在该控制器中定义所有返回ActionResult的方法以重定向到视图,并且不确定是否最好的方法。
What is the correct way to do this? 正确的方法是什么?
Web API is not for views. Web API不适用于视图。 API stands for application programming interface - that is, there is no user interface (views) that a user can interact with.
API代表应用程序编程接口 -即,没有用户可以与之交互的用户界面(视图)。
There is another framework with view functionality built-in: ASP.NET MVC . 还有一个内置视图功能的框架: ASP.NET MVC 。 It will even run side-by-side within your Web API project - see How to add MVC to existing web API project .
它甚至可以在您的Web API项目中并行运行-请参阅如何将MVC添加到现有的Web API项目 。
So in short: 简而言之:
System.Web.Mvc.Controller
) System.Web.Mvc.Controller
继承) System.Web.Http.ApiController
) when you want to return data to an application or browser. System.Web.Http.ApiController
继承)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.