asp:文字数据绑定特性
我有一个网站,它严重依赖克里奥尔解析器来允许在网站的多个区域(维基本身、论坛等)进行维基格式化。
在维基中,我使用 Literal
控件来显示呈现的文本(包含从原始克里奥尔语文本呈现的实际 HTML 元素)。代码基本上如下:
<asp:literal id="renderedText" runat="server" />
----
string creoleText = db.GetTable<Wiki>().Where(w => w.ID == id).Single().CreoleText;
RenderEngine engine = new RenderEngine();
renderedText.Text = engine.Render(creoleText);
一切正常。
但是,尝试通过数据绑定和使用 asp:Repeater
完成同样的事情,我似乎无法渲染文本。基本上我正在这样做:
<asp:repeater id="conversationRepeater" runat="server">
<!-- header template, itemtemplate, etc -->
<tr><td>
<asp:literal runat="server"
text='<%# DataBinder.Eval(Container.DataItem, "Content") %>' />
</td></tr>
----
RenderEngine engine = new RenderEngine();
var forumConversation = db.GetTable<ThreadMessage>()
.Select(t => new ThreadMessage
{
ID = t.ID,
Content = engine.Render(t.Content)
}
);
conversationRepeater.DataSource = forumConversation;
conversationRepeater.DataBind();
我最终得到的是原始的克里奥尔语文本,而不是带有我需要的实际 HTML 元素的渲染文本。
I have a website that relies heavily on a Creole parser for allowing wiki formatting in several areas of the site (the wiki itself, the forum, etc.)
In the wiki,Ii use a Literal
control to display the rendered text (that contains actual HTML elements rendered from the original creole text). The code is basically as follows:
<asp:literal id="renderedText" runat="server" />
----
string creoleText = db.GetTable<Wiki>().Where(w => w.ID == id).Single().CreoleText;
RenderEngine engine = new RenderEngine();
renderedText.Text = engine.Render(creoleText);
and everything works just fine.
However, trying to accomplish the same thing via data binding and using an asp:Repeater
, I can't seem to get the text to render. Basically I'm doing this:
<asp:repeater id="conversationRepeater" runat="server">
<!-- header template, itemtemplate, etc -->
<tr><td>
<asp:literal runat="server"
text='<%# DataBinder.Eval(Container.DataItem, "Content") %>' />
</td></tr>
----
RenderEngine engine = new RenderEngine();
var forumConversation = db.GetTable<ThreadMessage>()
.Select(t => new ThreadMessage
{
ID = t.ID,
Content = engine.Render(t.Content)
}
);
conversationRepeater.DataSource = forumConversation;
conversationRepeater.DataBind();
and I just end up with the original creole text, not the rendered text with actual HTML elements that I need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我会发布我所采用的解决方案。这真的很简单。我只是创建了渲染引擎的静态版本,并在其中创建了一个可以在数据绑定表达式中使用的扩展方法:
完成。
Figured I'd post the solution I went with. It was quite simple really. I just create a static version of my Render Engine and in it, created an extension method that I could use in my databinding expressions:
Done.