Note: Below is just a small demo sort to simulate what i am looking for:
Below are the urls format on my app that user can see
mydomain.com/cat/1 --display cat with id 1 |controller=Cat, action=DisplayDetails
mydomain.com/dog/2 --display dog with id 2 |controller=Dog, action=DisplayDetails
mydomain.com/cow/2 --display cow with id 3 |controller=Cow, action=DisplayDetails
I have maintained a system where no 2 animals(may be of different kind) can have same id, it means if there is a cat with id=1, we cant have any other animal with that id. Also from my system i can extract animal details+ type just from animal id
Apart from existing URL pattern, I am planning to create a short Url in format as below
mydomain.com/1 --this will show cat
mydomain.com/2 --this will show dog
mydomain.com/3 --this will show cow
Routes i have created are as below, and they appear same order in global.asax
pattern= Cat/{id}, controller= Cat, action=DisplayDetails
pattern= Dog/{id}, controller= Dog, action=DisplayDetails
pattern= Cow/{id}, controller= Cow, action=DisplayDetails
pattern= {id}, controller= DisplayAnyAnimal ----------i want help in this Route
Currently Controller looks like this
public class DisplayAnyAnimalContoller : Controller
{
public ActionResult Index(string animalId)
{
//iam processing request here from animalId
//now i know which contoller+action needs to be executed
//say for instant i have to display dog with id=2
//currently iam doing this to redirect and its working fine,
//but it changes url
-----------------------------------------------
#########################
### i need help here ###
#########################
return RedirectToRoute(new {contoller="Dog",action="DisplayDetails",id=2 });
-----------------------------------------------
}
}
Now the problem with RedirectToRoute
/ RedirectToAction
is they both changes the URL. But i dont want to change my url pattern.
Please suggest me how to achieve this, you may suggest some entirely different way, to achieve this