Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试从我的 SQL 数据库中生成一个嵌套的无序列表。我使用递归方法来嵌套数据。我应该将我的逻辑放在单独的 htmlhelper 中,还是应该使用调用子操作方法的 Html.RenderAction?
评估我将使用的两个选项Html.RenderAction,如果您使用 anhtmlhelper您必须找到一种方法将该菜单模型传递给您的所有视图以便htmlhelper可以呈现 html,您将需要使用ActionFilterand ViewData/ViewBag来传递模型。
Html.RenderAction
htmlhelper
ActionFilter
ViewData
ViewBag
有了Html.RenderAction控制器可以使用自己的模型来处理工作,因此您不必处理复杂的模型或ViewData/ViewBag对象和铸件,您还可以获得缓存[OutputCache]和控制的好处[ChildActionOnly]。
[OutputCache]
[ChildActionOnly]