最近我開始在我的Web控件中更頻繁地使用<%=
。通常我會在Code Behind中設置String屬性,然後將它們吐出到表單上。在WebControl中使用`<%=`是否是一個糟糕的主意
這是一個壞主意嗎?
例如。
代碼背後:
屬性:
public string TheTitle { get; set; }
public string TheBody { get; set; }
public ContentItem TheContent { get; set; }
public string ContentId {
get
{ return "content" + (TheContent != null) ? TheContent.Id.ToSTring() : "0"; }
}
的Page_Load:
TheTitle = TheContentItem.Title;
TheBody = TheContentItem.Body;
上頁:
<div id='<%= ContentID %>'>
<h2 class='title'><%= TheTitle ?? "No Title" %></h2>
<p><%= TheBody %></p>
</div>
你能詳細說明你爲什麼認爲這可能是一個壞主意嗎? – Robaticus 2010-09-07 21:20:37
如果您要在CodeBehind中使用ViewModel類型屬性的所有麻煩,爲什麼不移動到MVC? – mwjackson 2010-09-07 21:36:02
其實,我正在轉向新項目的MVC。但我不會重寫舊的。 – Armstrongest 2010-09-08 15:21:39