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的相关方法。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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); } }
下面来详细解释下。
一共有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>不理解的可以看这里
![](https://pic.cnblogs.com/avatar/567748/20200111202800.png)
出处:http://www.cnblogs.com/kmsfan
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
欢迎大家加入KMSFan之家,以及访问我的优酷空间!