【发布时间】:2010-11-19 18:32:46
【问题描述】:
我正在使用 ASP.NET MVC 1.0 / C# 为客户构建帮助台票证系统。我已经实现了 Steven Sanderson 的“App Areas in ASP.NET MVC, Take 2”,效果很好。
在我的 Globabl.asax 页面中,我定义了一些路由:
public static void RegisterRoutes(RouteCollection routes)
{
// Routing config for the HelpDesk area
routes.CreateArea("HelpDesk", "ProjectName.Areas.HelpDesk.Controllers",
routes.MapRoute(null, "HelpDesk/{controller}/{action}", new { controller = "Ticket", action = "Index" }),
routes.MapRoute(null, "HelpDesk/Ticket/Details/{TicketId}", new { controller = "Ticket", action = "Details", TicketId = "TicketId" })
);
}
所以,如果我在浏览器地址栏中手动输入“http://localhost/HelpDesk/Ticket/Details/12”,我会得到我期望的结果。这是我的控制器:
public ActionResult Details(int TicketId)
{
hd_Ticket ticket = ticketRepository.GetTicket(TicketId);
if (ticket == null)
return View("NotFound");
else
return View(ticket);
}
在我看来,我有:
<%= Html.ActionLink(item.Subject, "Details", new { item.TicketId } )%>
但该代码会生成“http://localhost/HelpDesk/Ticket/Details?TicketId=12”,它也会返回预期结果。我的问题是……
在使用 Steven Sanderson 的 Areas 时如何定义 ActionLink,它将创建一个干净的 URL,例如:“http://localhost/HelpDesk/Ticket/Details/12”?
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-routing