我正在使用带有C#代码隐藏的ASP.Net控件,并在视图中包含以下代码:
<div class="article span4">
<h5><%= article.Title %></h5>
<p><%= article.Summary %></p>
</div>
<div class="media span4">
<h5><%= media.Title %></h5>
<img src="<%= media.ImageUrl %>" />
</div>
代码隐藏只是:
public partial class Content : System.Web.UI.UserControl
{
public ContentModel article = new ContentModel();
public ContentModel media = new ContentModel();
protected void Page_Load(object sender, EventArgs e)
{
article.Title = "Foobar";
article.Summary = "Foobar";
media.Title = "Foobar";
media.ImageUrl = "Foobar";
}
public class ContentModel
{
public string Url { get; set; }
public string Title { get; set; }
public string ImageUrl { get; set; }
public string VideoID { get; set; }
public string Summary { get; set; }
}
}
渲染时,它只显示:
<div class="article span4">
<h5></h5>
<p></p>
</div>
<div class="media span4">
<h5></h5>
<img src>
</div>
我还在代码隐藏中有一个ContentModel列表,并在foreach中通过视图迭代它,并且它可以成功运行。