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.

 
 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。