我正在为使用 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 的区域时如何定义 ActionLink将创建一个干净的 URL,例如:“ http://localhost/HelpDesk/Ticket/Details/12 ”?