webApi添加视图出现/Index.cshtml”处的视图必须派生自 WebViewPage 或 WebViewPage。
程序员文章站
2022-03-15 10:14:45
是因为webApi Views文件夹下缺乏web.config文件,从mvc项目相同目录拷贝一个web.Config文件放入 删除多余的namespaces 即可 web.config配置如下: ......
是因为webapi views文件夹下缺乏web.config文件,从mvc项目相同目录拷贝一个web.config文件放入 删除多余的namespaces 即可
web.config配置如下:
<?xml version="1.0"?> <configuration> <configsections> <sectiongroup name="system.web.webpages.razor" type="system.web.webpages.razor.configuration.razorwebsectiongroup, system.web.webpages.razor, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"> <section name="host" type="system.web.webpages.razor.configuration.hostsection, system.web.webpages.razor, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" requirepermission="false" /> <section name="pages" type="system.web.webpages.razor.configuration.razorpagessection, system.web.webpages.razor, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" requirepermission="false" /> </sectiongroup> </configsections> <system.web.webpages.razor> <host factorytype="system.web.mvc.mvcwebrazorhostfactory, system.web.mvc, version=5.2.3.0, culture=neutral, publickeytoken=31bf3856ad364e35" /> <pages pagebasetype="system.web.mvc.webviewpage"> <namespaces> <add namespace="system.web.mvc" /> <add namespace="system.web.mvc.ajax" /> <add namespace="system.web.mvc.html" /> <add namespace="system.web.optimization"/> <add namespace="system.web.routing" /> </namespaces> </pages> </system.web.webpages.razor> <appsettings> <add key="webpages:enabled" value="false" /> </appsettings> <system.webserver> <handlers> <remove name="blockviewhandler"/> <add name="blockviewhandler" path="*" verb="*" precondition="integratedmode" type="system.web.httpnotfoundhandler" /> </handlers> </system.webserver> <system.web> <compilation> <assemblies> <add assembly="system.web.mvc, version=5.2.3.0, culture=neutral, publickeytoken=31bf3856ad364e35" /> </assemblies> </compilation> </system.web> </configuration>