【发布时间】:2011-07-10 09:30:13
【问题描述】:
注意:下面只是一个小的演示排序来模拟我正在寻找的内容:
以下是用户可以在我的应用上看到的网址格式
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
我维护了一个系统,其中没有 2 只动物(可能是不同种类的)可以有相同的 id,这意味着如果有一只 id=1 的猫,我们不能有任何其他具有该 id 的动物。同样从我的系统中,我可以仅从动物 ID 中提取动物详细信息+类型
除了现有的 URL 模式,我打算创建一个短 URL,格式如下
mydomain.com/1 --this will show cat
mydomain.com/2 --this will show dog
mydomain.com/3 --this will show cow
我创建的路由如下,它们在 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
目前的 Controller 是这样的
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 });
-----------------------------------------------
}
}
现在RedirectToRoute / RedirectToAction 的问题是它们都更改了 URL。但我不想改变我的 url 模式。
请建议我如何实现这一目标,您可能会提出一些完全不同的方式来实现这一目标
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 asp.net-routing