如何将MVC添加到现有的Web API项目 [英] How to add MVC to existing web API project

查看:277
本文介绍了如何将MVC添加到现有的Web API项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我有一个Web api项目,我想添加一个可以创建用户和修改权限的管理页面,但是,实际上几乎没有关于如何将MVC添加到现有Web api项目中的文档.

Currently I have a web api project that I want to add an admin page that can create users and modify permissions, however there appears to be virtually no documentation on how to add MVC to an existing web api project.

推荐答案

我在使用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>

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆