I'm practicing ASP.NET MVC routing and now I'm stuck at a situation which I don't understand how to solve. I have two controllers and action in both controllers and two routes in RouteConfig class - which looks like this:
routes.MapRoute(
name: "Students",
url: "{Class}/{Students}",
defaults: new { controller = "Class", action = "Students" });
routes.MapRoute(
name: "SubjectDetail",
url: "{Class}/{Subject}",
defaults: new { controller = "Subject", action = "SubjectDetail"});
Now the problem is when I go to the class/Students URL, it works fine, but in case of class/subject, it again redirects me to the class/Students URL.
I know there is some route pattern mistakes. How to solve this issue?
Thanks
but in case of class/subject it again redirects me to the class/Students-- That's because both of your routes have the same signature. How is the routing engine supposed to differentiate between a student and a subject, if both URLs look the same?