2013-01-25 47 views
2

猫我在@helper函数上创建一个委托?razor @helper返回什么类型?

@helper DisplayCategoryTree(int? parentId) 
{  

    Func<Category, CategoryNode, MvcHtmlString> act = new Func<Category, CategoryNode, MvcHtmlString>(GetChildItem); 
    act(Category, CategoryNode); 

} 

@helper GetChildItem(Category, CategoryNode) 
{  


} 

回答

5

剃刀佣工返回System.Web.WebPages.HelperResult它实现IHtmlString这样你就可以用这个来代替MvcHtmlString

所以这个声明应该很好地工作:

@helper DisplayCategoryTree(int? parentId) 
{  

    Func<Category, CategoryNode, IHtmlString> act = 
     new Func<Category, CategoryNode, IHtmlString>(GetChildItem); 
    act(Category, CategoryNode); 
} 

@helper GetChildItem(Category, CategoryNode) 
{  
} 
+0

我想补充一点,我写了深入的文章关于HTML助手,将教你几乎一切关于他们。 http://www.simple-talk.com/dotnet/asp.net/writing-custom-html-helpers-for-asp.net-mvc/ –