企业对企业的网站,乐清网站优化推广,营销型网站的推广方法,商品展示网站模板前言 在新建完一个MVC项目之后#xff0c;你会发现整个整个项目结构中存在有两个web.config文件#xff0c;如下图所示#xff1a; 这两个配置文件#xff0c;一个位于项目的根目录下面#xff0c;一个位于Views文件夹下面#xff0c;这两个配置文件有什么不同呢#xf… 前言 在新建完一个MVC项目之后你会发现整个整个项目结构中存在有两个web.config文件如下图所示 这两个配置文件一个位于项目的根目录下面一个位于Views文件夹下面这两个配置文件有什么不同呢 一、根目录下面的配置文件 跟目录下面的web.config配置文件代码如下 ?xml version1.0 encodingutf-8?
!--有关如何配置 ASP.NET 应用程序的详细信息请访问https://go.microsoft.com/fwlink/?LinkId301880--
configurationappSettingsadd keywebpages:Version value3.0.0.0/add keywebpages:Enabled valuefalse/add keyClientValidationEnabled valuetrue/add keyUnobtrusiveJavaScriptEnabled valuetrue//appSettingssystem.webcompilation debugtrue targetFramework4.6.1/httpRuntime targetFramework4.6.1//system.webruntimeassemblyBinding xmlnsurn:schemas-microsoft-com:asm.v1dependentAssemblyassemblyIdentity nameAntlr3.Runtime publicKeyTokeneb42632606e9261f/bindingRedirect oldVersion0.0.0.0-3.5.0.2 newVersion3.5.0.2//dependentAssemblydependentAssemblyassemblyIdentity nameSystem.Diagnostics.DiagnosticSource publicKeyTokencc7b13ffcd2ddd51/bindingRedirect oldVersion0.0.0.0-4.0.2.1 newVersion4.0.2.1//dependentAssembly dependentAssemblyassemblyIdentity nameNewtonsoft.Json publicKeyToken30ad4fe6b2a6aeed/bindingRedirect oldVersion0.0.0.0-11.0.0.0 newVersion11.0.0.0//dependentAssemblydependentAssemblyassemblyIdentity nameSystem.Web.Optimization publicKeyToken31bf3856ad364e35/bindingRedirect oldVersion1.0.0.0-1.1.0.0 newVersion1.1.0.0//dependentAssemblydependentAssemblyassemblyIdentity nameWebGrease publicKeyToken31bf3856ad364e35/bindingRedirect oldVersion1.0.0.0-1.6.5135.21930 newVersion1.6.5135.21930//dependentAssemblydependentAssemblyassemblyIdentity nameSystem.Web.Helpers publicKeyToken31bf3856ad364e35/bindingRedirect oldVersion1.0.0.0-3.0.0.0 newVersion3.0.0.0//dependentAssemblydependentAssemblyassemblyIdentity nameSystem.Web.WebPages publicKeyToken31bf3856ad364e35/bindingRedirect oldVersion1.0.0.0-3.0.0.0 newVersion3.0.0.0//dependentAssemblydependentAssemblyassemblyIdentity nameSystem.Web.Mvc publicKeyToken31bf3856ad364e35/bindingRedirect oldVersion1.0.0.0-5.2.4.0 newVersion5.2.4.0//dependentAssembly/assemblyBinding/runtimesystem.webServermodulesremove nameTelemetryCorrelationHttpModule/add nameTelemetryCorrelationHttpModuletypeMicrosoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelationpreConditionintegratedMode,managedHandler//modules/system.webServersystem.codedomcompilerscompiler languagec#;cs;csharp extension.cstypeMicrosoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version2.0.0.0, Cultureneutral, PublicKeyToken31bf3856ad364e35warningLevel4 compilerOptions/langversion:default /nowarn:1659;1699;1701/compiler languagevb;vbs;visualbasic;vbscript extension.vbtypeMicrosoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version2.0.0.0, Cultureneutral, PublicKeyToken31bf3856ad364e35warningLevel4 compilerOptions/langversion:default /nowarn:41008 /define:_MYTYPE\quot;Web\quot; /optionInfer//compilers/system.codedom
/configuration 这个配置文件主要是用来配置数据库连接字符串、日志输出路径等信息的比如配置数据库连接字符串 二、Views文件夹下面的配置文件 Views文件夹下面的配置文件主要是用来引入一些cshtml页面中的命名空间 在上一篇文章中我们如果要再cshtml视图页面中使用Student实体类需要首先在页面中引入Student的命名空间 如果cshtml页面都需要使用到Student类那么每个页面都需要先引入Student类的命名空间才可以使用这样会有很多重复的工作可以把Student类的命名空间添加到Views文件夹下的配置文件中这样就不需要每个页面都引入Student类的命名空间了 然后把ViewDataDemo对应的Index视图修改如下 *引入Student的命名空间*
*using MVCStudyDemo.Models; 去掉引入Student命名空间在web.config文件里面引入 *
{ViewBag.Title Index;// 这里使用的是Razor语法写的是后台C#代码// ViewData的Value值是Object类型的需要进行类型转换// 常规写法是先在这里进行类型转换var list ViewData[Data] as ListStudent;
}h2通过ViewData向View传递数据/h2
div classjumbotrondivdiv1、传递字符串 other:ViewData[Other];/divdiv2、传递字符串 name:ViewData[name];/divdiv3、传递字符串 age:ViewData[age];/divdiv4、传递集合方式一foreach (var item in list){divID:item.IDnbsp;nbsp;Name:item.Namenbsp;nbsp;Age:item.Agenbsp;nbsp;Sex:item.Sexnbsp;nbsp;Email:item.Email/div}/divdiv5、传递集合方式二foreach (var item in ViewData[Data] as ListStudent){divID:item.IDnbsp;nbsp;Name:item.Namenbsp;nbsp;Age:item.Agenbsp;nbsp;Sex:item.Sexnbsp;nbsp;Email:item.Email/div}/div/div
/div 注意在Index视图里面去掉命名空间以后Student实体类会标红不影响程序。 重新生成程序然后运行 转载于:https://www.cnblogs.com/dotnet261010/p/11417746.html