为什么.NET生成一个MVC asp.net适用的两个web.config文件中? [英] Why does .NET generate two web.config files in an MVC asp.net application?

查看:340
本文介绍了为什么.NET生成一个MVC asp.net适用的两个web.config文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的MVC 3,什么是使用两个web.config文件中的原因是什么?

I am new in MVC 3. What is the reason to use two web.config files?

那是什么2 web.config文件中的区别,什么是每个和它的功能的目的是什么?

What is difference between that 2 web.config files, and what is the purpose of each and its function?

推荐答案

我想补充一点,在/浏览文件夹中的Web.Config是一个伟大的(如果不是)的方式来专门用于声明命名空间的意见。在Web应用中它是非常有可能的,几乎每一个观点得到传递给它一个视图模型(而不是实际的模型)。声明@model后完整的命名空间或具有相同@using App.Web.Viewmodels变得乏味。这样,所有的ViewModels自动可用,你必须做额外的工作来获得范围真正的模型,那么这应该设置一些警钟立刻

I'd like to add to this that the Web.Config in the /Views folder is a great (if not thé) way to declare namespaces specifically for your views in. In a web application it is very possible almost every view gets a ViewModel (instead of your actual model) passed to it. Declaring the full namespace after @model or having the same @using App.Web.Viewmodels gets tedious. This way, all viewmodels are automatically available and you have to do extra work to get the real models in scope, which should then set of some alarm bells immediatly.

此外,通常是一个应用程序可以得到很多延伸的方法专门用于在视图(HTML辅助跳入脑海)使用。这是有道理的命名空间定义在/Views/Web.Config这个扩展类。你永远不知道这样,为什么不能智能感知找到@ Html.ImageLink()方法?!

Also, usually an application can get a lot of extension-methods specifically for use in the view (the HTML-helper jumps into mind). It makes sense to define the namespace to this extension class in the /Views/Web.Config. That way you never wonder "Why cant IntelliSense find the @Html.ImageLink() method??!"

这篇关于为什么.NET生成一个MVC asp.net适用的两个web.config文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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