I am working on a classified website that will have links like "electronics/mobiles/samsung/samsungS3/adTitle". How to create hierarchy of views like that in asp.net. If the answer is HMVC then please refer some link that contains complete guide how to implement HMVC.
2 Answers
You don't need hierarchy of Views, you should use Route Config that will allow you to get View that you need base on URL.
From 4 Version of MVC also have areas not only controlles and View by default. So check this tutorial to know how to customise your Routing.

- 12,350
- 10
- 38
- 70
-
Thanks but what i want is that there should be separate query for each link like if link ends with "mobiles" it will show all ads in mobiles and if it ends with "samsung" it will show all mobile ads of samsung and so on – Irfan Y Jul 12 '15 at 13:09
-
1@IrfanWattoo you talking about controller params and you can use them in routing, like `id = UrlParameter.Optional` in default example, you can make something like `brand = UrlParameter.Optional` and use it in your controller like param that helps you to show right ad. – teo van kot Jul 12 '15 at 13:09
-
there will be only one view to display all types of ads but query will be different – Irfan Y Jul 12 '15 at 13:10
You don't need to create views in this hierarchy but you need to create URLs in this fashion and that is called friendly URLs.
Look at following stack overflow question How can I create a friendly URL in ASP.NET MVC? and Friendly URL
You will be defining another route which will end up on your single action method. So You will add a route in routeConfig.cs as follows
routes.MapRoute(
name: "custom",
url: "{category}/{type}/{manufacturer}/{version}/{Title}",
defaults: new { controller = "Home", action = "customRoute"}
);
and your custom action will have all values passed in as param be as follows
public string customRoute(string category, string type, string manufacturer, string version, string Title)
{
return category + type + manufacturer + version + Title;
}
You can achieve the same using action based routing as well
// eg: electronics/mobiles/samsung/samsungS3/adTitle
[Route("{category}/{type}/{manufacturer}/{Title}")]
public ActionResult Index(string cateogry, string type,string manfacture, string Title) { ... }

- 1
- 1

- 1,766
- 2
- 23
- 41
-
Thanks haseeb but i don't want to make friendly URL. There should be separate query for each link like if link ends at "mobiles" it will show all ads in mobiles and if it ends with "samsung" it will show all mobile ads of samsung and so on. – Irfan Y Jul 12 '15 at 12:50
-
You can achieve that as well using this approach. Creating separate folder for each mobile manufacturer isn't scale-able (Extendible) because you will required to add new vendors every now and then. – Haseeb Asif Jul 12 '15 at 12:56
-
there will be only one view to display ads but query will be different. This is what i wanted – Irfan Y Jul 12 '15 at 13:02