我无法获取定义自定义编辑器的当前项目。
我需要获取当前页面(文章)的 ID,但Sitecore.Context.Item
返回 null。如何从当前项目中获取 id?
UPD:
编辑器 aspx 文件正在测试工作
<asp:Repeater ID="Comments" runat="server">
<ItemTemplate>
<div>
<b><%# DataBinder.Eval(Container.DataItem, "Name")%></b>
<p><%# DataBinder.Eval(Container.DataItem, "Text")%></p>
</div>
</ItemTemplate>
<SeparatorTemplate><hr /></SeparatorTemplate>
</asp:Repeater>
cs (Page_Load):
protected void Page_Load(object sender, EventArgs e)
{
var currentItem = Sitecore.Context.Database.GetItem(Request.QueryString["id"]);
using (var connection = new SqlConnection(@"..."))
{
var query = "SELECT Name, Text from dbo.Comments " +
"WHERE Article = @CurrentItemId";
var command = new SqlCommand(query, connection);
command.Parameters.Add("@CurrentItemId", System.Data.SqlDbType.UniqueIdentifier).Value = currentItem.ID.ToGuid();
try
{
connection.Open();
var list = new List<Comment>();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
list.Add(new Comment(reader[0].ToString(), reader[1].ToString()));
}
Comments.DataSource = list;
Comments.DataBind();
reader.Close();
}
finally
{
connection.Close();
}
}
}