asp.net mvc 2 - MVC Areas and routing -
I have to be an area called "product", where I can use routes such as
/ P> /products/views/foo/index.aspx/areas/products/views/bar/index.aspx
I see images, etc. specially Want to keep related to each product (foo, bar) in your respective / region / products / views / (foo | times) / folder
I do not even want to add a controller action for each product.
If I declare a route
context.MapRoute ("product-show-product", "product / {ID}", new {controller = " Product ", Action =" Index ", ID = UrlParameter.Optional});
and url request
Then
is ProductsController.Index ()
It is said, as I used to expect, however, "afu" is not visible in scene view / products or ideas / shared folder, so it is not being found.How can I do this so that I can put the pages of each product in one separate folder?
I do not have a solid answer to your question because I'm not sure about it though , I feel normal for the direction for the solution.
When someone starts changing the places of thoughts, then there is a need to change the same way to find those ways. There will be a simple way to override the FindView
and FindPartialView
methods.
A simple demo I created an area called blog, with a blog controller with an index method. In my case I use the user as the subfolder of the controller, but I am sure that it can be extended in your case for each product folder. I think the product will be a request argument.
The basic idea is to interrogate the Controller Contrast for Controller, Area, Action and ID and to modify what appears to be the default viewing. The default location for area views looks like "~ / Areas / {2} / views / {1} / {0} .aspx"
, so we basically have a value for the view name And the case the verb / index
in this case. The view location will end in ~ / region / blog / view / blog / index / index.aspx
.
This is just a rough framework that can be used. String comparisons can definitely be updated for more robust methods. As this stands, this method will be worked as expected for the entire app, except in case of any request made in the blog area for index action. Public Controller ViewPrint Finder View (Controller Content Controller Contains, String View Name, String MasterName, Bull Usage Cache) {if (Controller Consort. RouteData.DataTokens ["Region"] == "Blog") {if (String Toastring) "Index", true) == 0) {var viewLocation = String.Format ("{0} / {1}", Controlled consort. Route data. Value ["action"]. ToString (), viewName); Return base Fundwave (Controller Consult, Scene Location, MasterName, Usage Cache); }} Return base.FindView (Controlling music, visual name, mastername, user); }
Comments
Post a Comment