我正在为使用ASP.NET MVC 1.0/C#的客户端构建一个帮助台票务系统。我已经实施了史蒂文桑德森的“App Areas in ASP.NET MVC, Take 2”,它工作得很好。手动ASP.net MVC区域和创建一个带ID(SEO /干净URL)的ActionLink
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”,我得到我预期的结果:
在我Globabl.asax页我定义为这样一些途径。这里是我的控制器:
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”?
Womp ...有它!你是对的。这是命令! – robnardo 2009-08-17 12:48:21