我繼承下面的代碼,我想知道如果我能在你的大腦挑來看看有沒有做重複這個更好的方式。需要幫助想出一個更好的HtmlHelper擴展方法
繼承人我們大多數部分輸入的HTML視圖
<% if (Html.IsInputReadOnly()) { %>
<td>
Id
</td>
<td>
<%= Html.TextBox(
"Id"
, (Model == null ? null : Model.Id)
, new { @readonly = "readonly", @disabled="disabled" }
)%>
<% } elseif (Html.IsInputDisplayable() == false) { %>
<td></td>
<td></td>
<% } else { %>
<td>Id</td>
<td><%= Html.TextBox("Id")%>
<%= Html.ValidationMessage("Id", "*")%>
</td>
<%} %>
這裏是我的entension方法
public static bool IsInputReadOnly(this HtmlHelper helper)
{
string actionName = ActionName(helper);
// The Textbox should be read only on all pages except for the lookup page
if (actionName.ToUpper().CompareTo("EDIT") == 0)
return true;
return false;
}
public static bool IsInputDisplayable(this HtmlHelper helper)
{
string actionName = ActionName(helper);
// The Textbox should be read only on all pages except for the lookup page
if (actionName.ToUpper().CompareTo("CREATE") == 0)
return true;
return false;
}
在此先感謝
我同意的意見必須是愚蠢的,但在什麼的情況下,「控制x應爲條件1被啓用,但是對於條件2禁用」的情況的?所以,我給這個問題+1。 – Sunny 2010-02-10 18:04:13