2015-04-02 141 views
0

在我BLOCKDATA型我已经EpiServer.Url如何设置EpiServer.Url属性通过

public virtual EpiServer.Url Url { get; set; }

类型的财产从编辑模式下,我能够设置混凝土PageData实例,但我m不知道如何将它设置为只有ContentReference的代码?

在此先感谢您的帮助。

编辑

我发现这样做的一个方式是通过:

var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>(); 
int contentReferenceId = 69; 
ContentReference contentRef = new ContentReference(contentReferenceId); 
block.Url = urlResolver.GetUrl(contentRef, language.Code); 

我会很高兴,如果有人可以点我一个更好的解决方案,如果有的话。

+0

像约翰建议,你不希望保存一个实际的URL,而只是对内容的引用。 – 2015-04-04 21:31:56

+0

是的,您是对的,但EditMode中的EpiServer.Url属性可以将其设置为EpiServer中的页面链接或指向外部页面的链接,甚至是其他内容。这就是为什么我没有接受Johan的答案。 – 2015-04-06 12:29:12

回答

1
publich virtual ContentReference Url { get; set; } 

或者,如果你只想网页:

publich virtual PageReference Url { get; set; } 
相关问题