DataContract
数据契约
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, FuncdefaultContentFunc) { 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>不理解的可以看