2014-01-08 50 views
0

現在我正在開發一個項目,在那裏我必須顯示帶有url選擇器數據類型的標題導航,爲此我花了兩個字段:Text(Text String)&鏈接(Url Picker)。如何從Umbraco中的url中刪除節點ID和擴展

爲了得到這個導航鏈接這一點,我已經做了下面的代碼:

Default.aspx的

<asp:Repeater ID="rptMainNavListing" runat="server" OnItemDataBound="rptMainNavListing_OnItemDataBound"> 
       <HeaderTemplate> 
        <div class="header_top_links_right"> 
         <ul> 
       </HeaderTemplate> 
       <ItemTemplate> 
        <li> 
         <asp:HyperLink ID="hlLink" runat="server"> 
         </asp:HyperLink> 
         <asp:Literal ID="ltText" runat="server"></asp:Literal> 
        </li> 
       </ItemTemplate> 
       <FooterTemplate> 
        </ul> 
         </div> 
       </FooterTemplate> 
      </asp:Repeater> 

Default.aspx.cs

using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using Reshape.Framework; 
using Reshape.Framework.UI; 
using Reshape.Framework.Constants; 
using umbraco.NodeFactory; 

namespace Reshape.UserControls { 
    public partial class Header : BaseLayout { 
     protected void Page_Load(object sender, EventArgs e) { 
      if (!IsPostBack) { 
       Node currentNode = Common.GetMainNavigationFolder(); 
       var childList = currentNode.Children; 
       rptMainNavListing.DataSource = currentNode.Children; 
       rptMainNavListing.DataBind(); 
     } 
     } 

     protected void rptMainNavListing_OnItemDataBound(object sender, RepeaterItemEventArgs e) { 
      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { 
       Node itm = e.Item.DataItem as Node; 
       if (itm != null) { 
        Literal ltText = (Literal)e.Item.FindControl("ltText"); 
        HyperLink hlLink = e.Item.FindControl("hlLink") as HyperLink; 
        if (ltText != null) { 
         ltText.Text = itm.GetProperty("text").Value; 
        } 
        if (hlLink != null) { 
         hlLink.NavigateUrl = itm.Url; 
         hlLink.Text = itm.GetProperty("link").Value; 
        } 
       } 
      } 
     } 
    } 
} 

調試這個代碼我得到URL後以下形式(編號爲&延期)

False1154/regions.aspxRegions 
here id =False1154 
extension =regions.aspx 

我只想要網址像「地區」。

回答

0

更改您的代碼以下面的代碼....你會擺脫這個問題:-)

if (childList.Count > 0) { 
        rptMainNavListing.DataSource = childList; ; 
        rptMainNavListing.DataBind(); 

       } 

直放站代碼

protected void rptMainNavListing_OnItemDataBound(object sender, RepeaterItemEventArgs e) { 
      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { 
       Node itm = e.Item.DataItem as Node; 
       if (itm != null) { 
        Literal ltText = (Literal)e.Item.FindControl("ltText"); 
        HyperLink hlLink = e.Item.FindControl("hlLink") as HyperLink; 
        if (itm.GetProperty(FieldName.LINK) != null && !string.IsNullOrEmpty(itm.GetProperty(FieldName.LINK).Value)) { 
         hlLink.NavigateUrl = umbraco.library.NiceUrl(Convert.ToInt16(itm.GetProperty(FieldName.LINK).Value)); 
        } 
        hlLink.Text = itm.GetProperty(FieldName.TEXT).Value; 
       } 
      } 
     }