I have 2 controllers which are SearchController and SearchByStaffController respectively. They are very similar and both have an action with action name “Search”. When I call View(“Search”) in their common super class, the confusion comes. Only the “Search” view with SearchController is rendered.
- Does the MVC framework get only the first view that matches the name and ignore the rest?
- I tried to pass the view path in View() and it worked. Would there be any side effect for doing so? I searched over the web and seems no one has done this before.
Thanks!
Yes. The routing rules are aparsed (top to bottom) and when a rule is matched all end.
You can but I don’t like that because MVC is based on conventions. So, I see forcing the path of the view a way to broke a convention. Are you sure you can’t simply create two routing rules for the two methods? So you can do something like this:
and