Kooboo CMS - Html.FrontHtml.Position 详解

DataContract

数据契约

http://www.cnblogs.com/Gavinzhao/archive/2010/06/01/1748736.html

https://msdn.microsoft.com/zh-cn/library/system.runtime.serialization.datacontractattribute.aspx

 

Html.FrontHtml.Position("main") 详解

1.首先我们打开工程文件,在搜索框里写上FrontHtml查找到FrontHtmlHelper类,如下图:

下面是关于Position的相关方法。

        #region Position
        public virtual IHtmlString Position(string positionID)
        {
            return Position(positionID, "");
        }

        public virtual IHtmlString Position(string positionID, string defaultContent)
        {
            return Position(positionID, () => defaultContent);
        }
        public virtual IHtmlString Position(string positionID, Func<string> defaultContentFunc)
        {
            if (PageContext.PageRequestContext.RequestChannel == FrontRequestChannel.Design)
            {
                return new PageDesignHolder(this, positionID);
            }
            else
            {
                var positions = GetContentsForPosition(positionID);
                if (positions.Length == 0)
                {
                    defaultContentFunc = defaultContentFunc == null ? () => "" : defaultContentFunc;
                    return new HtmlString(defaultContentFunc());
                }
                else
                {
                    var htmlStrings = RenderPositionContents(positions).ToArray();
                    return new AggregateHtmlString(htmlStrings);
                }

            }
        }

        public virtual IHtmlString Position(string positionID, bool requireMembershipAuthentication, params string[] membershipGroups)
        {
            if (PageContext.PageRequestContext.RequestChannel == FrontRequestChannel.Design)
            {
                return new PageDesignHolder(this, positionID);
            }
            else
            {
                if (requireMembershipAuthentication)
                {
                    var permission = new PagePermission() { RequireMember = requireMembershipAuthentication, AllowGroups = membershipGroups };
                    if (!permission.Authorize(Html.ViewContext.HttpContext.Membership().GetMember()))
                    {
                        return new HtmlString("");
                    }
                }
                return Position(positionID);
            }
        }
View Code

下面来详细解释下。

一共有4个重载函数分别是:

public virtual IHtmlString Position(string positionID)

public virtual IHtmlString Position(string positionID, string defaultContent)

public virtual IHtmlString Position(string positionID, Func<string> defaultContentFunc)

public virtual IHtmlString Position(string positionID, bool requireMembershipAuthentication, params string[] membershipGroups)

 

这里如果有不明白的话可以,可以参考一下以下的知识:

1.positionID的意思就是你的HTML元素的ID。

2.如果对() => defaultContent)不理解的人,可以参看这里

3.对于Func<string>不理解的可以看这里

 

posted @ 2015-04-04 12:18  yangliwen  阅读(942)  评论(0编辑  收藏  举报
document.getElementById("homeTopTitle").innerText="ღKawaii";