且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将MVC添加到现有的Web API项目

更新时间:2021-07-03 23:29:07

我在使用WebApi但未使用MVC的项目中遇到类似的问题,后来使用以下方法添加MVC:

I had a similar Problem with a Project using WebApi but not MVC and used the following Approach to add MVC later on:

  • 我使用块金将Microsoft.AspNet.Mvc以及Microsoft.AspNet.Web.Optimization添加到了项目中
  • 我向App_Start文件夹添加了一个RouteConfig文件(由MVC模板创建),并在Global.asax.cs类中执行了方法RegisterRoutes,再次对应于一个新的MVC项目.这允许控制器被调用.
  • 我添加了控制器(主页)和新视图(Index.cshtml).添加视图创建了Shared/_Layout.cshtml和_ViewStart.cshtml文件

启动项目后,它导致我收到以下错误消息:

Once I started the project, it resulted in me getting the following error message:

视图必须派生自WebViewPage或WebViewPage< TModel>