在MVC 3中創建一個站點,我有這個代碼片段,我在設計的幾個部分使用。這是一個爲網站上的模塊創建頭像的設計代碼。 現在想知道這是否是調用此代碼段的最佳方式?我應該使用助手還是有更好的方法?MVC 3,最好的方法來調用這個HTML
今天我這樣做:
public static IHtmlString FrameModuleHeader(this HtmlHelper helper, int Type, string Headline)
{
StringBuilder html = new StringBuilder();
html.Append("<div class='module_top'>");
html.Append("<div class='module_top_left'></div>");
html.Append("<div class='module_top_middle_" + Type + "'><div class='module_top_headline'><h4>" + Headline + "</h4></div></div>");
html.Append("<div class='module_top_right'></div>");
html.Append("</div>");
return MvcHtmlString.Create(html.ToString());
}
然後通過調用視圖中的我的HTML助手:
@ Html.FrameModuleHeader(1, 「我的標題」)
謝謝! /Mike