类库中的控制器和视图 [英] Controllers and Views inside a Class Library

查看:59
本文介绍了类库中的控制器和视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组在许多项目中使用的控制器和视图.我想知道是否可以将其放在类库中,然后将其作为普通的lib文件重用. 我该怎么办?

I've a group of controllers and Views that I use in many projects. I was wondering if I could place then inside a class library and reuse it as a normal lib file. How can I do this?

推荐答案

绝对可行.您需要做的事情:

Definitely doable. Things you'll need:

  1. 通过某种方式在应用启动时注册路线.
  2. 一个了解引擎视图和您的应用程序特定视图的视图引擎.

第一个很简单.只需在您的库中编写一个在库中注册所有控制器的函数即可.

The first is easy. Just write a function in your library that registers all the controllers in the library.

第二个更为复杂,但是您可以阅读一些有关编写自己的视图引擎的好文章,

The second is more complicated, but you can read some good articles on writing your own view engine, here and here. The concept of Areas may be useful too for separating your library controllers from your app controllers.

此外,这个问题解决了在任意文件夹中查找视图的最简单情况.

Also, this question addresses the simplest case of finding views in an arbitrary folder.

这篇关于类库中的控制器和视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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