在以下示例中,
如何在MyUserControl中将
我不是在谈论像
对于在ASP.NET MVC 3中工作的解决方案,奖励积分!
编辑:
感谢StriplingWarrior和此链接作为缺失的拼图,魔法就这样实现了:
所以,在任何视图中:
在Ribbon.ascx中:
<uc1:MyUserControl>
<p>this is html</p>
</uc1:MyUserControl>
如何在MyUserControl中将
"<p>this is html</p>"
作为字符串访问,以便我可以将其注入响应中?我不是在谈论像
<uc1:MyUserControl myparameter="<p>this is html</p>" />
这样传递字符串参数,而是如何访问真正的多行智能化HTML标记,无论是在开放和关闭标记之间还是通过其他机制(例如<MessageTemplate>
标记)。对于在ASP.NET MVC 3中工作的解决方案,奖励积分!
编辑:
感谢StriplingWarrior和此链接作为缺失的拼图,魔法就这样实现了:
所以,在任何视图中:
<%@ Register src="../../Shared/Ribbon.ascx" tagname="Ribbon" tagprefix="uc1" %>
...
<uc1:Ribbon ID="Ribbon" runat="server">
<Content>
Hello world! I am <b>pure html</b> being passed into a UserControl!
</Content>
</uc1:Ribbon>
在Ribbon.ascx中:
<%@ Control Language="C#" CodeBehind="Ribbon.ascx.cs" Inherits="NunYourBeezwax.Views.Shared.Ribbon" %>
<table>
<tr>
<td>I am reusable stuff that wraps around dynamic content</td>
<td><%= this.Content %></td>
<td>And I am stuff too</td>
</tr>
</table>
最后,在Ribbon.ascx.cs中(需要在MVC中手动添加)
using System.Web.Mvc;
using System.Web.UI;
namespace NunYourBeezwax.Views.Shared
{
[ParseChildren(true, "Content")]
public class Ribbon : ViewUserControl
{
[PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty)]
public string Content { get; set; }
}
}
将呈现为:
<table>
<tr>
<td>I am reusable stuff that wraps around dynamic content</td>
<td>Hello world! I am <p>pure html<p> being passed into a UserControl!</td>
<td>And I am stuff too</td>
</tr>
</table>