Reputation: 69
I have to add a new route in my RouteConfig.cs but it is only working if I remove one of the current route. Is there anyway around this? Is there a better way to do this ? should it key off of the RouteCollection?
Current
routes.MapHttpRoute("FhirSearch", "fhir/{type}", new { controller = "Fhir", action = "Search" });
New
routes.MapHttpRoute("FhirDiseasesList", "fhir/DiseasesList", new { controller = "Fhir", action = "DiseasesList" });
This also Conflicting
routes.MapHttpRoute("FhirDiseasesList", "fhir/Diseases/List", new { controller = "Fhir", action = "DiseasesList" });
Upvotes: 1
Views: 39
Reputation: 6185
but it is only working if I remove one of the current route
I think both of your route works fine but what happens is the routing engine executes the route that is indicated first. So-- whichever route comes first that matches your url, that is the one that's going to be executed.
Like separate the word diseases
and list
in your new route.
routes.MapHttpRoute("FhirSearch", "fhir/Diseases/List", new { controller = "Fhir", action = "DiseasesList" });
public ActionResult Search(string type)
{
if(type == "DiseasesList"){
return redirectToAction("DiseasesList");
}
... // do something else
}
EDIT: OP mentioned without the specific routing, it would hit Search action
For routes.MapHttpRoute("FhirRead", "fhir/{type}/{id}", new { controller = "Fhir", action = "Read" });
you could add a constraint to only match id
with integers.
routes.MapHttpRoute(
"FhirRead",
"fhir/{type}/{id}",
new { controller = "Fhir", action = "Read" },
new {id = @"\d+" } // routing constraint to only match id with integers
);
Upvotes: 1