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

查看:22
本文介绍了为什么 .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?

这两个 web.config 文件有什么区别,每个文件的用途和功能是什么?

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

推荐答案

我想补充一点,/Views 文件夹中的 Web.Config 是一种很好的(如果不是)方式来声明专门为您的命名空间视图中.在 Web 应用程序中,几乎每个视图都有可能获得一个传递给它的 ViewModel(而不是您的实际模型).在@model 之后声明完整的命名空间或具有相同的@using App.Web.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 中为这个扩展类定义命名空间是有意义的.这样你就不会想知道为什么 IntelliSense 找不到我的 @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 my @Html.ImageLink() method??!"

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

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