My url is as follow: www.example/videos/category1,category2,category3/sex/hospital/doctor But in my url category1 and category2 and category3(may be 1 or too many) can be null/empty. Also sex or hospital or doctor also can be null. How can i detect which one is null. If categories is null. Then mvc sense sex as categories and hospital as sex. What kind of approach i can use?
Asked
Active
Viewed 65 times
0
-
1I suggest you use parameters: http://stackoverflow.com/questions/2246481/routing-with-multiple-parameters-using-asp-net-mvc – Nick Jul 09 '13 at 14:09
-
Thanks. But my scenario is different from it. – ftdeveloper Jul 09 '13 at 14:15
1 Answers
1
MVC cannot tell if an earlier URL part is null over it being a different route.
If your route is:
videos/{categories}/{subcategory1}/{subcategory2}/{subcategory3}/
All are optional. But if categories are different than the other subcategories, you'll need to have a placeholder for when it is null. Basically you'll need another route for when categories are null.
context.MapRoute(
"video_nocategories",
"videos/all/{subcategory1}/{subcategory2}/{subcategory3}/",
new
{
action = "Index",
controller = "Video",
categories = "",
subcategory1 = UrlParameter.Optional,
subcategory2 = UrlParameter.Optional,
subcategory3 = UrlParameter.Optional,
}
);
context.MapRoute(
"video_categories",
"videos/{categories}/{subcategory1}/{subcategory2}/{subcategory3}/",
new {
action = "Index",
controller = "Video",
subcategory1 = UrlParameter.Optional,
subcategory2 = UrlParameter.Optional,
subcategory3 = UrlParameter.Optional,
}
);

smdrager
- 7,327
- 6
- 39
- 49