我正在爲使用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