使用路线数据作为模型过滤器?
也许我对这一切的看法都是错误的。
我有一个大表,其中有 3 个“分类”列。这些分类名称是 MVC 的理想控制器/操作名称。
但是
控制器/操作名称所做的只是过滤到表中的某些行,它不会创建要在视图中显示的唯一模型。有没有更好的方法来看待这个问题?
ID | CAT1 | CAT2 | CAT3 | DETAILS | 1 | a1 | b1 | c1 | foo | ... x | a2 | b2 | c2 | bar | ... n | a3 | b3 | c3 | fun | ...
/a1/b2/c3/ 路由将产生与 /a3/b3/c1 路由相同的“数据对象”。我对 MVC 的(有限)理解在这里没有意义,因为不同的路线应该使用不同的模型。
如何让所有这些操作使用同一视图?
代码类似于
/drills/hydraulic/ --> WHERE(CAT1="a2" AND CAT2="b3")
/loaders/tracked/ --> WHERE(CAT1="x3" AND CAT2="r3")
/hauling/rails/ --> WHERE(CAT1="c8" AND CAT3="b7")
所以所有 3 个 URL 将使用相同的视图,但是不同的控制器/操作。 看来我没有“正确”使用该模式,因为我有很多控制器,但几乎没有任何视图。
Maybe I'm looking at this all wrong.
I've got a large table with 3 'classification' columns. These classification names are ideal controller/action names for MVC.
BUT
All the controller/action name does is filter down to certain rows in the table, it doesn't create unique models to display in a view. Is there a better way to be looking at this?
ID | CAT1 | CAT2 | CAT3 | DETAILS | 1 | a1 | b1 | c1 | foo | ... x | a2 | b2 | c2 | bar | ... n | a3 | b3 | c3 | fun | ...
A Route of /a1/b2/c3/ will result in the same 'data object' as a route of /a3/b3/c1. My (limited) understanding of MVC isn't making sense here, as different routes should be using different models.
How do I get all these actions to use the same view?
Code would be something like
/drills/hydraulic/ --> WHERE(CAT1="a2" AND CAT2="b3")
/loaders/tracked/ --> WHERE(CAT1="x3" AND CAT2="r3")
/hauling/rails/ --> WHERE(CAT1="c8" AND CAT3="b7")
So all 3 URL's would be using the same View, but are different controllers/actions.
It seems like I'm not using the pattern 'properly' as I've got lots of controllers, but hardly any views.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您需要在路由中添加一个控制器 - 就像 ClassificationController 一样。它将有一个方法:
然后您的路由将如下所示:
...您的路由将如下所示:
/classification/cat1/cat2/cat3
现在您有一个由单个控制器处理的单个视图(Index.aspx) (分类控制器)。
这是你所需要的吗?
It sounds like you need to add a single controller into your routing - like a ClassificationController. It would have a single method:
Then your routing would look like this:
...and your routes would look like this:
/classification/cat1/cat2/cat3
Now you have a single View (Index.aspx) handled by a single Controller (ClassificationController).
Is this what you needed?