开发者

Adding Areas to a hybrid MVC-Webforms application

开发者 https://www.devze.com 2023-04-02 03:45 出处:网络
I am adding MVC support to a legacy ASP.NET Website project. I have added a separate class library for the Controllers and the Views are in the legacy app. It works great so far, but I\'d like to take

I am adding MVC support to a legacy ASP.NET Website project. I have added a separate class library for the Controllers and the Views are in the legacy app. It works great so far, but I'd like to take advantage of Areas. Since Areas encapsulate Controllers, Views and Models, if i add a new class project to host the Areas then would it work with the Views in 开发者_C百科this project?

Also, Areas need a web.config file and I assume I cant add a web.config to a class library Areas project.

Is this even possible?


I don't think the View files can be placed outside of the MVC3 project (it has to know where to find the files).

You can, however, specify a namespace for your Area routes that specifies where to search for your Controllers (so your controllers can remain in a separate project).

context.MapRoute("routename",
  "{controller}/{action}",
  new { controller="Home",action="Index"},
  null,
  new[] {"ControllerProject.NamespaceTo.Controllers"}
);


You will need to be sure you reference the proper ProjectTypeGuids in your project file.

http://www.kevinrohrbaugh.com/blog/2009/7/17/demystifying-the-aspnet-mvc-project-type.html

Be sure you have added the proper references for MVC as well. When all is configured, visual studios should allow you to right click the project and add areas with the supporting structure.

0

精彩评论

暂无评论...
验证码 换一张
取 消