开发者

Use Route Data as Model Filter?

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'开发者_JS百科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.


It sounds like you need to add a single controller into your routing - like a ClassificationController. It would have a single method:

public ActionResult Index(string cat1, string cat2, string cat3)
    {
        //...load from table and return data to the view
    }

Then your routing would look like this:

routes.MapRoute("ClassificationIndex", "classification/{cat1}/{cat2}/{cat3}", new { controller = "classification", action = "index" });

...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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜