转:ASP.NET MVC 3 and App_Code folder

问题:

In ASP.NET Webform, App_Code is standardfolder to putting code and using it at run-time.But I think this folder is kind of different in ASP.NET MVC, my question is:

  • where should I put my code ( Extension methods , Helpers , ... ) in ASP.NET MVC. When I store code in App_Code folder, I can‘t use theme in controller but they work fine in views.
  • About Entity Framework, the same question, where should I put edmx and tt files. I‘m not using Code-First

Update:

After some search, finally I created a new Class Library project in my solution, code is available in allcontrollers and views. I still don‘t know why the code in App_Code is not available in controller

回答 :

App_Code is necessary in Web Site projects because it has a special meaning. It means "Don‘t serve these files to a web browser". In ASP.NET MVC, files are not directly served to the browser in most cases, so App_Code is not necessary. You can place code files whereever you want, in any folder you want.

Using a stand-alone library is also a fine solution.

时间: 2024-10-14 08:40:26

转:ASP.NET MVC 3 and App_Code folder的相关文章

ASP.NET MVC项目中App_Code目录在程序应用

学习ASP.NET MVC,如果你是开发ASP.NET MVC项目的,也许你去为项目添加前ASP.NET项目的APP_Code目录,在这里创建与添加的Class类,也许你无法在MVC项目所引用. 那这样说,是不是一没有作用了呢?非也. 从下面一步一步来学习. 创建一个model,名称:Machine using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Insu

CRUD Operations In ASP.NET MVC 5 Using ADO.NET

Background After awesome response of an published by me in the year 2013: Insert, Update, Delete In GridView Using ASP.Net C#. It now has more than 140 K views, therefore to help beginners I decided to rewrite the article i with stepbystep approach u

Professional C# 6 and .NET Core 1.0 - Chapter 41 ASP.NET MVC

What's In This Chapter? Features of ASP.NET MVC 6 Routing Creating Controllers Creating Views Validating User Inputs Using Filters Working with HTML and Tag Helpers Creating Data-Driven Web Applications Implementing Authentication and Authorization W

Asp.Net Mvc Razor视图语法

    Asp.Net Mvc Razor视图语法 [email protected]符号输出变量值 2.使用C#语法嵌套Html标签循环输出NameList的值:使用@{C#语法代码}: 3.输出@符号使用两个@@ 4.服务器注释使用@*注释内容*@ [email protected]:输出文本,或者使用<text></text> 6.在@()括号进行简单的操作或运算 [email protected]()或@{}可以输出带有html标签的字符串 8.Razor可以智能识别邮箱写

LowercaseRoutesMVC ASP.NET MVC routes to lowercase URLs

About this Project Tired of your MVC application generating mixed-case URLs like http://mysite.com/Home/About orhttp://mysite.com/Admin/Customers/List? Wouldn't http://mysite.com/home/about andhttp://mysite.com/admin/customers/list be a lot nicer? I

NHibernate构建一个ASP.NET MVC应用程序

NHibernate构建一个ASP.NET MVC应用程序 什么是Nhibernate? NHibernate是一个面向.NET环境的对象/关系数据库映射工具.对象/关系数据库映射(object/relational mapping,ORM)这个术语表示一种技术,用来把对象模型表示的对象映射到基于SQL的关系模型数据结构中去. NHibernate 是一个基于.Net 的针对关系型数据库的对象持久化类库.NHibernate 来源于非常优秀的基于Java的Hibernate 关系型持久化工具.

在asp.net mvc中上传大文件

在asp.net mvc 页面里上传大文件到服务器端,需要如下步骤: 1. 在Control类里添加get 和 post 方法 1 // get method 2 public ActionResult Upload() 3 { 4 return View(); 5 } 6 7 // This action handles the form POST and the upload 8 [HttpPost] 9 public ActionResult Upload(HttpPostedFileBa

ASP.NET MVC使用Bootstrap系列(5)——创建ASP.NET MVC Bootstrap Helpers

序言 ASP.NET MVC允许开发者创建自定义的HTML Helpers,不管是使用静态方法还是扩展方法.一个HTML Helper本质上其实是输出一段HTML字符串. HTML Helpers能让我们在多个页面上公用同一段HTML标记,这样不仅提高了稳定性也便于开发者去维护.当然对于这些可重用的代码,开发者也方便对他们进行单元测试.所以,创建ASP.NET MVC Bootstrap Helpers是及其有必要的. 内置的HTML Helpers ASP.NET MVC内置了若干标准HTML

[asp.net mvc 奇淫巧技] 02 - 巧用Razor引擎在Action内生成Html代码

在web开发中经常会遇到在内部代码中获取Html,这些Html是需要和数据进行一起渲染.并不是直接把Html代码返回给客户端.这样的做法有很多应用场景,例如分页.Ajax一次性获取几段Html片段.生成邮件发送模板.生成Html静态页面等等.比较简单的或者容易想到的做法就是直接拼接Html,当然这肯定不是最合适的做法. 应用场景 1.在分页中,有一种做法是用ajax获取table的html代码和一些分页信息的Json var json = { "table": "<ta