编辑模板的最佳实践。净MVC3

时间:2021-09-03 20:08:11

I am using:

我用:

  • Asp.net MVC3
  • Asp.net MVC3
  • Ninject
  • Ninject
  • Repository pattern with Entity Framework 4.0
  • 具有实体框架4.0的存储库模式

On an admin page there is a select where the user can choose a product group. The dropdown is in a partial view in EditorTemplates. The partial view today handles the data access itself. My question is, what is the best practice for this partial view?

在管理页面上有一个选择,用户可以在其中选择产品组。下拉菜单位于EditorTemplates的部分视图中。今天的部分视图处理数据访问本身。我的问题是,这种片面观点的最佳实践是什么?

Is it:

它是:

  1. Keep it as it is
  2. 保持原样
  3. Move the select to a view that is rendered by an Action, so that the Controller can get its dependencies from Ninject
  4. 将select移动到由操作呈现的视图中,这样控制器就可以从Ninject中获得它的依赖项
  5. The Partial View gets both the ID of the product group selected AND all the groups from the view that invokes it.
  6. 分部视图从调用它的视图中获取所选产品组的ID和所有组。
  7. ?
  8. 吗?

Above i described a specific scenario, but I guess that it is a common problem, and I haven't found a good way of doing it on SO.

上面我描述了一个特定的场景,但是我想这是一个常见的问题,我还没有找到一个好的方法来解决它。

2 个解决方案

#1


1  

As long as the partial view is called once, I'd go with option 2. I'd look into MiniProfiler to see all the calls to the database. You shouldn't be doing much of that if any in your views. If it's being called for each item in the select or if you have the data already, it would be faster to pass that data directly to the view.

只要局部视图调用一次,我就使用选项2。我将查看MiniProfiler以查看对数据库的所有调用。在你的观点中,你不应该这么做。如果select中的每个项都被调用,或者您已经拥有数据,那么将数据直接传递到视图将会更快。

#2


1  

I don't know, how much this answers you question, but I would go with option 2 :)

我不知道这个答案能回答你多少问题,但我会选择第二种

#1


1  

As long as the partial view is called once, I'd go with option 2. I'd look into MiniProfiler to see all the calls to the database. You shouldn't be doing much of that if any in your views. If it's being called for each item in the select or if you have the data already, it would be faster to pass that data directly to the view.

只要局部视图调用一次,我就使用选项2。我将查看MiniProfiler以查看对数据库的所有调用。在你的观点中,你不应该这么做。如果select中的每个项都被调用,或者您已经拥有数据,那么将数据直接传递到视图将会更快。

#2


1  

I don't know, how much this answers you question, but I would go with option 2 :)

我不知道这个答案能回答你多少问题,但我会选择第二种