〜/Views/Web.config及其内容 [英] ~/Views/Web.config and its content

查看:55
本文介绍了〜/Views/Web.config及其内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从零开始创建一个网站,并且使用了MVC模式.

I'm creating a website since zero, and I've used the MVC pattern.

〜/Web.config具有对某些DLL的程序集引用,但是〜/Views/Web.config有什么?是的,此文件阻止了对控制器等的访问.但是,例如,此文件正在添加名称空间(以及更多内容).为什么这是必需的?

~/Web.config has the assembly references to some DLLs, but what has ~/Views/Web.config? Yes, this file block the access to the controllers and more., but this file is adding namespaces (and more things), for example. Why is this necessary?

<?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.2.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" />
        <add namespace="WebApplication4" />
      </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>
</configuration>

推荐答案

它设置基本页面类型:

<pages pageBaseType="System.Web.Mvc.WebViewPage">

没有上面的行,您必须像这样在每个视图上进行设置:

Without the above line you would have to set it on each view like this:

@inherits System.Web.Mvc.WebViewPage

WebViewPage 具有将MVC与Razor集成的 Html Url 之类的属性.

WebViewPage has properties like Html and Url that integrate MVC with Razor.

这篇关于〜/Views/Web.config及其内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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