3
該代碼與MVC 2一起工作良好,但不適用於MVC 3 Razor。一旦加載頁面,就不會像下面那樣從Rails中調用HTMLHelper加載菜單。Razor輸出在MVC 3中不起作用,但在MVC 2中工作2
用於測試哪些不在頁面上輸出的硬編碼菜單。
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using myproject.Extensions;
public static class MenuHelper
{
public static string TabbedMenu(this HtmlHelper helper, IEnumerable<MenuTab> tabs)
{
//I have hard coded menu for testing purpose.
return "<div class='menu-image'><img src='/content/Images/common/on-left.gif' alt='' /></div><div class='on'><a class='over' href='/?Length=4'>Home</a></div><div class='menu-image'><img src='/content/Images/common/on-right.gif' alt='' /></div><a href='/Home/About'>About</a><a href='/Home/Contact'>Contact</a>";
}
}
以下是Razor CSHTML代碼。在@{ ... }
@{Html.TabbedMenu
(
new List<MenuTab>
{
MenuTab.Create("Home", "Index", "Home"),
MenuTab.Create("About", "About", "Home"),
MenuTab.Create("Contact", "Contact", "Home")
}
);}
好的改變這個如下 公共靜態HtmlString TabbedMenu(此的HtmlHelper助手,IEnumerable的標籤) { \t回報新HtmlString( 「HTML菜單這裏上」); } @ Html.TabbedMenu ( \t新名單 \t { \t \t MenuTab.Create( 「家」, 「索引」, 「家」), \t} ) 誤差低於 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)'的最佳重載方法匹配有一些無效參數 無法從'方法組'轉換爲'System.Web.WebPages.HelperResult'\t c :\ Path myproject –
Pirzada
2010-11-26 19:07:34