转:ASP.NET MVC 3 and App_Code folder

ASP.NET MVC代码组织
本文探讨了在ASP.NET MVC项目中如何合理地组织代码,包括扩展方法、辅助类等的存放位置,以及Entity Framework的使用方式。作者指出,不同于Web Forms中的App_Code,MVC项目中的代码可以更灵活地放置,并推荐使用独立的类库来组织共享代码。

问题:

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.

 
 

转载于:https://www.cnblogs.com/gdlixiaoyu/p/4554807.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值