您可以創建一個DynamicNodeProvider來處理這種情況。循環播放時只需添加「相關」節點,以便它們全部顯示在一起。該id存儲在RouteValues中並緩存給所有用戶,因此站點地圖不會在請求之間將其忘記。
public class EmployeeDynamicNodeProvider
: DynamicNodeProviderBase
{
CRUDExample db = new CRUDExample();
public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
{
var result = new List<DynamicNode>();
var employees = db.Employee;
foreach (var employee in employees)
{
var employeeKey = "Product_" + employee.Id.ToString();
// Create the "Details" node for the employee
var employeeNode = new DynamicNode(employeeKey, "EmployeeParentNodeKey", employee.Name, employee.Name, "Employee", "Details");
// Set the "id" route value so the match will work.
employeeNode.RouteValues.Add("id", employee.Id);
// Add the node to the result
result.Add(employeeNode);
// Create the "Edit" node for the employee
var employeeEditNode = new DynamicNode("EmployeeEdit_" + employee.Id.ToString(), employeeKey, "Edit", "Edit", "Employee", "Edit");
// Set the "id" route value of the edit node
employeeEditNode.RouteValues.Add("id", employee.Id);
// Add the node to the result
result.Add(employeeEditNode);
// Create the "Delete" node for the employee
var employeeDeleteNode = new DynamicNode("EmployeeDelete_" + employee.Id.ToString(), employeeKey, "Delete", "Delete", "Employee", "Delete");
// Set the "id" route value of the delete node
employeeDeleteNode.RouteValues.Add("id", employee.Id);
// Add the node to the result
result.Add(employeeDeleteNode);
// Create the "Demographics" node for the employee
var employeeDemographicsNode = new DynamicNode("EmployeeDemographics_" + employee.Id.ToString(), employeeKey, "Demographics", "Demographics", "Employee", "Demographics");
// Set the "id" route value of the delete node
employeeDemographicsNode.RouteValues.Add("id", employee.Id);
// Add the node to the result
result.Add(employeeDemographicsNode);
}
return result;
}
}
至於URL,它是System.Web.Routing,它將路由值轉換爲URL。但是,如果URL很複雜,則可以使用其他幾個選項:
- 使用站點地圖節點的Url屬性而不是路由值。
- 創建一個自定義URL解析器來處理URL的特殊情況。
謝謝你,也感謝你在這個項目上的工作......這是一個很棒的工具,我每天都在使用它。 – rodmjay